WEBVTT

00:04.560 --> 00:05.300
Welcome back.

00:05.310 --> 00:07.930
How did you go calculating that anger?

00:07.950 --> 00:13.320
Well, the first thing we're going to do is to work out the DOT product separately.

00:13.320 --> 00:19.710
So that's the V, W or in this case, it will be the tank forward dot the fuel direction.

00:19.710 --> 00:27.210
So we're going to create a float and we'll call it Dot and that's going to equal the tank forward dot

00:27.660 --> 00:45.210
x multiplied by the fuel direction, dot x plus the tank forward dot y multiplied by the fuel direction

00:45.210 --> 00:46.830
dot y.

00:47.550 --> 00:49.620
So that's our dot product.

00:49.620 --> 00:59.610
Now for the angle is going to be float angle equals math f dot a cosine.

01:01.240 --> 01:09.220
So a course from the math library and it it'll be the dot product divided by the multiplication of the

01:09.220 --> 01:12.940
two lengths of those vectors, these ones here.

01:13.300 --> 01:17.770
Now we've already found the length of vectors before and in fact a few times.

01:17.770 --> 01:27.400
So it's tank forward magnitude multiplied by the fuel direction dot magnitude.

01:27.630 --> 01:27.840
Okay.

01:27.880 --> 01:32.950
So that's basically working out that angle.

01:32.950 --> 01:35.140
So we can now just print that out.

01:35.140 --> 01:48.460
So underneath here, let's put in debug dot log angle that we're calculating plus angle and we'll multiply

01:48.460 --> 02:00.640
that by math f dot rad to degrees because by default most if not all of the angle mathematical functions

02:00.640 --> 02:08.080
are working with radians degrees make more sense to us, so we'll print them out in degrees.

02:08.080 --> 02:14.110
And then I'm also going to show you how you do it in unity or how unity can do it with its math.

02:14.110 --> 02:17.530
So unity angle plus.

02:18.190 --> 02:30.010
So it would be vector three dot angle, and we're finding the angle between the tank forward and the

02:30.160 --> 02:32.590
fuel direction.

02:34.270 --> 02:36.850
Isn't that a lot easier when you use the unity method?

02:36.850 --> 02:41.920
Now, notice also that the unity method is going to give it to you in degrees anyway.

02:41.920 --> 02:44.860
So if you read the help on that, it will show you.

02:44.860 --> 02:51.250
But at least now you know what's going on inside of this Angle method here and we've got our calculate

02:51.250 --> 02:54.740
angle, we've already added that down into our space bar haven't we.

02:54.760 --> 02:55.060
Yep.

02:55.070 --> 02:55.260
There.

02:55.270 --> 02:56.380
So let's save it.

02:56.380 --> 03:00.460
Let's go back into unity and we'll try this out.

03:01.720 --> 03:01.990
Okay.

03:02.140 --> 03:07.690
So straight away, let's just go to our console so we can see what we're working with and let's try

03:07.720 --> 03:08.080
this out.

03:08.080 --> 03:15.970
So we've got our angle is 66.7, eight, etc. and then the unity angle is 66.78 as well.

03:16.000 --> 03:16.320
Okay.

03:16.360 --> 03:18.280
So I press the spacebar.

03:18.310 --> 03:22.240
Remember, we're working out this angle here.

03:22.390 --> 03:32.110
Now, you should be able to sort of look at an angle and say, yes, that's probably about right, 66.7.

03:32.110 --> 03:38.500
If the tank was facing over in this direction and it was giving you 66.7, then you think, hold on,

03:38.500 --> 03:40.510
this angle is not right.

03:40.750 --> 03:47.020
So don't always go with the values that are given to you and just go by rope.

03:47.020 --> 03:47.860
Because I could be wrong.

03:47.860 --> 03:50.590
You could have calculated something slightly wrong.

03:50.650 --> 03:51.730
Okay, so let's have a look.

03:51.730 --> 03:58.090
Now, if we do this, we can see that our angle at calculating is almost 20 degrees in both cases,

03:58.090 --> 04:04.420
which is the angle from here to there, which looks about 20 degrees.

04:04.720 --> 04:11.260
So always use visual cues to check your mathematical equations.

04:11.380 --> 04:12.340
Okay, great.

04:12.340 --> 04:20.110
So that's the DOT product and that's working out the angle between the forward facing direction of a

04:20.110 --> 04:23.530
game character and the goal location where it needs to go to.

04:23.530 --> 04:29.650
And it's basically helping you work towards creating your own look at method that we implemented earlier

04:29.650 --> 04:31.270
with those pigs.

04:31.270 --> 04:37.210
When we come back in the next lecture, we're going to start looking at the cross product and what that

04:37.210 --> 04:38.470
will do for us.
