In the previous lecture, we started on a simple waypoint system.
In this lecture, are we going to work on getting our characters to progressively look at the location
that they're travelling towards rather than snapping around?
So we have to go back into our follow waypoint code and find our look at line.
So I'm just going to comment that out so that you can remember what we're trying to achieve here.
And instead, we're going to use the unity returnee and system.
So let's begin with creating a cartoon.
And so I can turn in stores a rotation.
So turn in.
Look at waypoint and that's going to equal turn in.
Dot look rotation.
Waypoints.
Current waypoint point.
Dot transform dot position.
Minus this dot transform dot position.
So that might seem familiar of getting your goal location minus the position of your character.
If you remember back to developing the vectors that we did where we were finding the direction vector
from your location to the goal.
So this is exactly the same thing you're giving your turn and look at a vector we're just going to use
as a rotation.
So that gives you what you need to rotate through to get from your current rotation of your tank to
facing in the right direction.
Though, we're only going to use a little proportion of this turn in the transform or this dot transform.
Dot rotation is actually stored as a turn in.
So instead of setting it to look at waypoint, which we could, what we're going to do is actually perform
what's called a slurp.
And slurp is spelt like you would expect, which is a spherical interpolation of the actual angle or
the rotation that you're going through.
And it basically means just turning a little bit through the whole angle.
So transform it.
Rotation.
Look at waypoint.
And then we're going to put our time, Delta time in here, which is the amount of rotation that you
want to do through that entire angle.
Let me just put this in front of here to be consistent, since I'm using it throughout.
Now, just like the speed here that you can set as a variable for how much speed you want, you can
also set how much rotation you want.
So let's put in a lot speed here and multiply that.
And then at the top we'll create a public float for Rod's speed.
And let's set that also to ten tens.
Always a good round number to start testing things with.
All right.
So we've got that.
Let's now save it and have a look at the effect.
So we will press play.
And what you're going to find is your tank is going to turn.
Quite smoothly around instead of snapping.
So what do you think's going to happen if we go back to our tank and now we change our rotational speed
down to, say, five?
Press play.
Okay.
Enough goes the tank.
And don't if you can tell a lot there, but it's taking longer to go through the entire turn.
Let's turn that down even more to one and you should start to really notice it.
It will start taking its time turning, which means you're going to get a much sort of smoother curve
that goes through all of these palm trees.
So you can see how he's starting to wiggle along that path.
Rather than taking the corners tightly as before.
Okay.
Now what happens if we change the rotational speed down to 0.5 and we have another go?
Let's press play.
Okay.
Right.
We have a situation where the tank is circling the waypoint.
Let me just focus in on that for you.
Now, what's happening here?
Well, you've seen this happening before.
We've had it with other characters that won't actually ever get to their goal location.
So what's happening in this instance is that the tank is trying to turn towards the tree, but it's
turning circle isn't tight enough, so it's never, ever going to get within a distance of three of
the tree in order for it to then switch over to the next waypoint.
So you've either got to go back into your code and make your distance threshold here of where you reach
a waypoint much larger.
So if we set this to say ten, I think that should be okay for such a.
Lazy turning vehicle.
Let's see if we can get within ten of that.
Okay.
So now it's considered to have been within ten.
Same for that one there.
But what you can also tell is, though, it's not very accurate.
Okay.
Because you're letting him have a lot of leeway as to whether he's reached a waypoint or not.
So I guess it's up to the effect that you actually want.
If you want them to sort of have quite a large turning circle, then you'll have to give them a little
bit more leeway in how they get with their accuracy to those actual palm trees.
But I'm going to set that back down to three.
Save that in the code and I will set my tax rotation back to, let's say, five so that we know now
that we're going to hit these waypoints.
But just know that if you ever get your tank or car or whatever you've got near a waypoint and it's
just going round and round and round the waypoint, it's because of your accuracy.
You can't hit the waypoint because it's not able to turn tight enough to reach that particular distance
that you're wanting it to right now.
I'm sure you're ready to put your script onto each of the tanks and have them race around the track.
So get hold of your follow waypoint script and start putting it on each of your tanks.
And don't forget to populate each of those waypoint arrays with all of the palm trees.
So when we press play, off they go.
Now, we don't have any physics elements on these at all, so they're just going to be on top of each
other, which really makes it quite a dull kind of simulation.
So what we're going to do in the next video is actually come back and start adding some physics elements
to our tanks.