Now, before we can start programming our car to self-drive, it needs to know where it's driving.
So we're actually going to create a circuit using waypoints.
And we should be pretty familiar with waypoints by now because they're used so much in A.I. for our
A.I. agents in games.
So we're going to create a simple script which will define our circuit as well as show you with some
gizmos what it looks like.
Okay, so let's go to create C-sharp sharp script.
Let's call it circuit and we will open that up.
Okay.
The first thing up here will be a public array of game objects, and these game objects will be markers
that show us where our circuit is going.
So we want game object and we'll put waypoints, we'll call it.
This will be slightly different way to the way we did waypoints before, but a lot of it will be familiar
to you, right?
So we don't want any of these things in here.
Let's get rid of these and we're going to create void on draw gizmos.
And this will be and then in here we'll put draw gizmos false.
And then down in here we want void on draw gizmos selected.
And this will allow us to actually just draw the circuit when we've got the circuit clicked.
This up here should actually be draw gizmos, not on draw gizmos.
Okay.
And then in here we want draw gizmos.
True.
Okay.
We haven't written drug gizmos, which is why it keeps flipping back on me.
Now, void draw gizmos.
Bool selected that in here will actually do the drawing.
So if selected equals false return.
If waypoints dot length is greater than one, then vector three previous way point here so previous
or prev equals waypoints zero dot transform dot position and then we're going to loop through the rest
of the waypoint.
So int i equals one is less than waypoints dot length.
I plus.
Plus.
Okay.
And then in here we'll draw the lines between them.
So vector three for the next waypoint will be equal to waypoints.
I transformed position and then gizmos dot draw line between previous and next and then we'll set the
previous to equal the next so that we move on to the next pair basically.
And then at the end of this will go gizmodo's dot draw line from whatever's now the previous to the
first waypoint which will be waypoints zero dot transform dot position.
Okay.
Right so you've got that code now let's save it and we will switch back into unity.
We're going to go into the hierarchy and create a empty game object.
Let's call that circuit and we will attach circuit here to circuit there.
So there's our circuit and is our waypoints.
Now we want to make some waypoints, so we're going to create a cube.
And here's my cube.
Now I want to move that cube down onto the ground.
Like this half way up because it's basically that center point in that cube that is marking where our
waypoint is.
Now, that cube, let's just call it waypoint like that.
Okay.
Now we're going to attach that cube to the circuit just to keep them all nice and cleanly put together.
Okay.
Now, with this waypoint, let's go control D and make another one.
Move it out here and make this quite a big track because the car is not a little car like, you know,
you can't make little tiny turns if the track is really, really tiny.
So let's just make something like this.
Okay, so there's our four waypoints.
Now, if you go back to the circuit in our waypoints, we can actually shift, select all of those.
And for our circuit, in fact, we actually have to lock that first so it doesn't disappear when we
select these drag these onto waypoints.
Okay.
So now they're all in there.
And if we click on circuit, you'll be able to see the circuit that has been created and it's going
to show up like that.
So what that means is if we go into our waypoints and maybe swap waypoint two with Waypoint one and
then click on the circuit, you can see now that this is the circuit and the way that it's going to
go.
But I actually don't want that way because it'll get a bit messy when we start trying to drive around
it.
So let's just put those back in so that we have a nice square round ish kind of circuit for the car
to go between.
So create as many of these waypoints that you like and then hook them up into the circuit and that will
give us a track for the car to follow.
All right.
So in the next video, we're going to come back and start putting in the code for the AI for this car
controller so that it can make its way around these waypoints.