WEBVTT

0
00:11.200 --> 00:17.320
In this lecture I want to talk about animation and how it affects your translation or moving of your

1
00:17.320 --> 00:19.980
characters. If you want to follow along,

2
00:20.080 --> 00:28.300
download the animation starter project with this lecture and open it up. Inside you'll find two characters,

3
00:28.300 --> 00:34.300
so I've got a zombie character and I've got the little lumberjack that we've used previously.

4
00:34.300 --> 00:42.880
Press Play and you'll find that they do the turning and the slerping, moving forward until they get to your

5
00:42.880 --> 00:48.610
goal cube, which you can also still drive around the scene.

6
00:48.620 --> 00:54.500
Now the problem with their animations at the moment if you have a look, is that they're skating or slipping

7
00:54.500 --> 00:56.100
along the ground.

8
00:56.120 --> 00:59.360
Now that's because we have them moving too quickly.

9
00:59.570 --> 01:07.430
So stop playing. The script that I've attached to each is MoveLocal and it's based on script that we've

10
01:07.430 --> 01:12.040
looked at before, but I've exposed the Speed so that we can change it.

11
01:12.110 --> 01:21.800
Let's change the speed for the lumberjack and for Jill the zombie down to 0.5. Ok, now press

12
01:21.800 --> 01:22.830
Play again.

13
01:24.930 --> 01:32.850
In the case of the lumberjack, he looks as though he's taking steps and propelling himself forward and

14
01:32.850 --> 01:35.230
there's not a lot of slippage in there.

15
01:35.460 --> 01:41.910
So he's walking cycle is quite simple, as far as one foot and the other. With Jill,

16
01:41.910 --> 01:47.580
she's got a much more complicated walking cycle, where she's not walking in a straight line.

17
01:47.580 --> 01:56.370
She's kind of slipping and skating her feet out from side to side and therefore inside of her animation.

18
01:56.400 --> 02:05.880
She has a forward-propelling movement and it's us trying to move that model with our code that is conflicting

19
02:06.180 --> 02:11.890
with her movements as well, that are already baked into her animation.

20
02:13.000 --> 02:19.900
Now I don't want to go into the complexities of Unity animation because it's opening up a huge can of

21
02:19.900 --> 02:25.770
worms, but I want to show you a couple of different things you can do to fix this problem.

22
02:25.780 --> 02:30.870
First of all, let's look at Jill because the lumberjacks animations are fine.

23
02:30.880 --> 02:38.570
So if you find that you can control your animated character, move it with your translations and get that aligned

24
02:38.620 --> 02:44.860
nicely so that the speed of the animation and the speed at which you're moving him with your code are nicely

25
02:44.860 --> 02:46.740
synchronized, then that's fine.

26
02:46.750 --> 02:52.900
But if you end up with a complicated model like this zombie, for example, then you may need a different

27
02:52.900 --> 02:55.350
way of propelling them forward.

28
02:55.360 --> 03:02.500
Luckily, the humanoid animation system in Unity already can propel characters forward based on their

29
03:02.500 --> 03:03.640
animation.

30
03:03.640 --> 03:09.910
So let's just go to Jill and what we're going to do is untick MoveLocal.

31
03:09.940 --> 03:16.480
We don't want that code on her. Then what we're going to do is drop down the Animator. The Animator has

32
03:16.480 --> 03:19.420
the animation control of the character on it.

33
03:19.420 --> 03:25.820
Now what you can do with a humanoid character is tick a box called Apply Root Motion.

34
03:26.020 --> 03:33.890
What this will do is move your character in the world, as the animation moves the character.

35
03:34.100 --> 03:41.740
If you press Play at the moment without any script on there, her animation is not moving her and that's why she's

36
03:41.740 --> 03:47.240
slipping on the ground because in her actual animation file, she would be moving forward.

37
03:48.060 --> 03:55.680
To see that, click on Jill and then over in the Inspector, tick on the Apply Root Motion box and then

38
03:55.680 --> 04:06.720
we'll just zoom in on Jill over here as well so we can see her moving. Then press Play and now without any code,

39
04:07.800 --> 04:15.780
the animation itself is moving her forward and see how much more natural it looks.

40
04:15.790 --> 04:23.280
Her feet look like they're planted and she's moving, but her forward motion isn't linear so therefore

41
04:23.280 --> 04:29.750
trying to drive it forward with a Translate is not going to work.

42
04:30.120 --> 04:35.610
If you have this kind of forward motion in your character already within the animation, then you

43
04:35.610 --> 04:40.950
should try and use that to your advantage. It'll make the movement of your character look so much more natural.

44
04:42.060 --> 04:51.420
So to test out using the animations to propel Jill forward, first of all turn back on the MoveLocal script

45
04:51.450 --> 04:52.220
that's on her.

46
04:52.230 --> 04:58.560
Then open up that script and what you want to do is remove any of the code related to pushing the character

47
04:58.560 --> 05:02.110
forward, which is indeed this transform

48
05:02.130 --> 05:08.760
down here at the bottom. We're also testing for distance and will need to comment that out as well, otherwise

49
05:08.760 --> 05:14.590
we're not doing anything when we've reached the goal. Save that and let's go back into Unity.

50
05:14.610 --> 05:18.680
What we're going to do with the lumberjack is turn him off, because we're not doing this for him

51
05:18.810 --> 05:27.420
and let's play Jill and we'll see now that her animations are driving her forward. She's still slipping

52
05:27.420 --> 05:30.580
because of that slerp that's in there.

53
05:30.600 --> 05:33.150
So that's also affecting it as well.

54
05:33.210 --> 05:40.950
You can see that her movement is just so much more natural now. To get her to turn around with the animation

55
05:40.950 --> 05:42.030
system itself,

56
05:42.030 --> 05:49.950
you would also need a zombie 'turn around' animation associated with it. Now because she's not reaching

57
05:49.950 --> 05:53.280
the goal (she's just going to circle round and round)

58
05:53.430 --> 05:59.810
at this point if you had an Idle animation, that's when you would set the animation to go to Idle

59
06:00.210 --> 06:06.960
and then she would obviously stop moving anywhere because we're only using the animation system to push

60
06:06.960 --> 06:08.540
her forward.

61
06:08.610 --> 06:15.390
So that is the difference between pushing her forward with the code and using what's in the animation

62
06:15.390 --> 06:17.490
system to push things forward.

63
06:17.490 --> 06:22.500
If you're interested in learning more about animation and this type of movement, then I do have another

64
06:22.500 --> 06:29.490
course on mastering animation in Udemy that you might like to have a look at, which will show you these

65
06:29.490 --> 06:34.110
differences and really get into the nuts-and-bolts of the animation system

66
06:34.200 --> 06:36.740
but for this course, we don't really have the time.