Welcome back.
How did you go calculating that anger?
Well, the first thing we're going to do is to work out the DOT product separately.
So that's the V, W or in this case, it will be the tank forward dot the fuel direction.
So we're going to create a float and we'll call it Dot and that's going to equal the tank forward dot
x multiplied by the fuel direction, dot x plus the tank forward dot y multiplied by the fuel direction
dot y.
So that's our dot product.
Now for the angle is going to be float angle equals math f dot a cosine.
So a course from the math library and it it'll be the dot product divided by the multiplication of the
two lengths of those vectors, these ones here.
Now we've already found the length of vectors before and in fact a few times.
So it's tank forward magnitude multiplied by the fuel direction dot magnitude.
Okay.
So that's basically working out that angle.
So we can now just print that out.
So underneath here, let's put in debug dot log angle that we're calculating plus angle and we'll multiply
that by math f dot rad to degrees because by default most if not all of the angle mathematical functions
are working with radians degrees make more sense to us, so we'll print them out in degrees.
And then I'm also going to show you how you do it in unity or how unity can do it with its math.
So unity angle plus.
So it would be vector three dot angle, and we're finding the angle between the tank forward and the
fuel direction.
Isn't that a lot easier when you use the unity method?
Now, notice also that the unity method is going to give it to you in degrees anyway.
So if you read the help on that, it will show you.
But at least now you know what's going on inside of this Angle method here and we've got our calculate
angle, we've already added that down into our space bar haven't we.
Yep.
There.
So let's save it.
Let's go back into unity and we'll try this out.
Okay.
So straight away, let's just go to our console so we can see what we're working with and let's try
this out.
So we've got our angle is 66.7, eight, etc. and then the unity angle is 66.78 as well.
Okay.
So I press the spacebar.
Remember, we're working out this angle here.
Now, you should be able to sort of look at an angle and say, yes, that's probably about right, 66.7.
If the tank was facing over in this direction and it was giving you 66.7, then you think, hold on,
this angle is not right.
So don't always go with the values that are given to you and just go by rope.
Because I could be wrong.
You could have calculated something slightly wrong.
Okay, so let's have a look.
Now, if we do this, we can see that our angle at calculating is almost 20 degrees in both cases,
which is the angle from here to there, which looks about 20 degrees.
So always use visual cues to check your mathematical equations.
Okay, great.
So that's the DOT product and that's working out the angle between the forward facing direction of a
game character and the goal location where it needs to go to.
And it's basically helping you work towards creating your own look at method that we implemented earlier
with those pigs.
When we come back in the next lecture, we're going to start looking at the cross product and what that
will do for us.