1
00:00:00,000 --> 00:00:00,000
Hello, guys.

2
00:00:00,000 --> 00:00:03,000
Now that you are familiar with the animations, I'm going to make something more at once.

3
00:00:03,000 --> 00:00:05,000
We're going to use a blend tree.

4
00:00:05,000 --> 00:00:10,000
Blend tree allows you to blend between animation according to different parameters.

5
00:00:10,000 --> 00:00:16,000
It can be used for 2D games just for jump and full animation, or it can be used even for 3D movement

6
00:00:16,000 --> 00:00:18,000
to the eight different directions.

7
00:00:18,000 --> 00:00:20,000
But today we're going to use simple one.

8
00:00:21,000 --> 00:00:26,000
Before we do that, I want to explain how jump and fall animation works in 2D games.

9
00:00:26,000 --> 00:00:33,000
So most of the time in the games, even like Mario or a boy, there is just a couple of frames for rise

10
00:00:33,000 --> 00:00:35,000
and Jump and for falling.

11
00:00:35,000 --> 00:00:41,000
It's done for different purposes and one of them is just to make your jump feel instant, because in

12
00:00:41,000 --> 00:00:46,000
the platformers jump is one of the most important aspects of the game and you want to see a jump work

13
00:00:46,000 --> 00:00:48,000
immediately, something like that.

14
00:00:48,000 --> 00:00:54,000
Let's go to graphics folder, open jump and we can see we have only jump and fall here and how it's

15
00:00:54,000 --> 00:00:54,000
going to work.

16
00:00:54,000 --> 00:00:58,000
You already know we're going to have an X and Y.

17
00:00:58,000 --> 00:01:02,000
So this is our Y and this is our X, right?

18
00:01:02,000 --> 00:01:05,000
And our characters are going to be here.

19
00:01:05,000 --> 00:01:09,000
And then when we press the space, we increase his velocity on the Y.

20
00:01:09,000 --> 00:01:15,000
So he goes up and when we're doing that, he's going to be in the rise in animation in this one.

21
00:01:15,000 --> 00:01:21,000
Then when he reaches highest point, he's going to go down and in that moment, velocity of the region

22
00:01:21,000 --> 00:01:26,000
by then the Y going to go down and we're going to change the animation to the fall to the second one.

23
00:01:26,000 --> 00:01:35,000
So first let's create two animations, create new clip assets, animations, player jump, drag the

24
00:01:35,000 --> 00:01:39,000
sprite and create new clip player fall and drag second Sprite.

25
00:01:40,000 --> 00:01:46,000
Now in the our animator, we can see we got two new animations but we're going to delete them.

26
00:01:46,000 --> 00:01:50,000
Click right button create from new blend tree.

27
00:01:52,000 --> 00:01:57,000
We're going to go over here and rename this blend parameter to Y velocity.

28
00:01:59,000 --> 00:02:00,000
Cool.

29
00:02:00,000 --> 00:02:06,000
Now we can take this bland tree and also rename it, and let's make it as a jump full.

30
00:02:07,000 --> 00:02:11,000
Now we're going to go inside of this blind tree, and we can do that by clicking twice on it.

31
00:02:11,000 --> 00:02:13,000
We are inside the blind tree.

32
00:02:13,000 --> 00:02:18,000
And here we can add two motions hit plus icon, choose, add motion field and one more.

33
00:02:19,000 --> 00:02:22,000
There's going to be a player full and player jump.

34
00:02:22,000 --> 00:02:28,000
If you don't have this window over here, you just need to drag your mouse from here and find it.

35
00:02:30,000 --> 00:02:37,000
Now let's uncheck out to my threshold and for the full animation, it's going to be minus one.

36
00:02:37,000 --> 00:02:39,000
For the jump, it's going to be one.

37
00:02:39,000 --> 00:02:46,000
So basically now if we drag this y velocity to the left, to the negative value, we can see we are

38
00:02:46,000 --> 00:02:47,000
in full animation.

39
00:02:47,000 --> 00:02:53,000
If we drag it to the right side, we can see we transferred to jump animation, right?

40
00:02:54,000 --> 00:02:56,000
So it works like that.

41
00:02:56,000 --> 00:03:00,000
And now we're going to control this velocity of the animator in code.

42
00:03:00,000 --> 00:03:11,000
Let's go to the script, find our animation controllers function and just type any set float of y velocity

43
00:03:12,000 --> 00:03:14,000
to RB, dot velocity dot y.

44
00:03:15,000 --> 00:03:16,000
Very simple.

45
00:03:18,000 --> 00:03:19,000
Let's go back.

46
00:03:24,000 --> 00:03:28,000
Okay, now we have this blind tree, but we don't have connection to player, idol and player move.

47
00:03:28,000 --> 00:03:31,000
So let's make it and to make it easier for us.

48
00:03:31,000 --> 00:03:36,000
Right now I want to drag this gray box which says any state and just make transition from any state

49
00:03:36,000 --> 00:03:37,000
to jump full.

50
00:03:37,000 --> 00:03:38,000
It means we can.

51
00:03:38,000 --> 00:03:39,000
It means what?

52
00:03:39,000 --> 00:03:43,000
It means we can transfer to this animation from any state that we have in the animator.

53
00:03:43,000 --> 00:03:50,000
Now we need a condition for that and I guess it's best to use boolean that we already have in the code

54
00:03:50,000 --> 00:03:51,000
is grounded.

55
00:03:51,000 --> 00:03:54,000
Let's create this boolean in the animator is grounded.

56
00:03:56,000 --> 00:04:00,000
Make transition to jump full if is grounded.

57
00:04:00,000 --> 00:04:00,000
True.

58
00:04:00,000 --> 00:04:03,000
And here I want to show you a handy trick.

59
00:04:03,000 --> 00:04:07,000
As you've seen when I hit plus icon, my first condition chosen is running.

60
00:04:07,000 --> 00:04:11,000
It is because it always chooses the first one in the list.

61
00:04:11,000 --> 00:04:15,000
So whenever you work with a new parameter, what you can do is just drag it on the top after creating

62
00:04:15,000 --> 00:04:16,000
it.

63
00:04:16,000 --> 00:04:19,000
And now every time you click condition, it's going to be on the top.

64
00:04:19,000 --> 00:04:21,000
So it's ground that should be false.

65
00:04:21,000 --> 00:04:24,000
Lets and remove transition duration.

66
00:04:28,000 --> 00:04:31,000
Now let's make another transition to player Idol.

67
00:04:33,000 --> 00:04:35,000
Let's uncheck exit time.

68
00:04:35,000 --> 00:04:39,000
Duration zero and condition will be is grounded.

69
00:04:39,000 --> 00:04:39,000
True.

70
00:04:41,000 --> 00:04:45,000
Now let's go back to code and add this boolean here.

71
00:04:45,000 --> 00:04:48,000
So I'll type anim set ball.

72
00:04:49,000 --> 00:04:51,000
Is grounded.

73
00:04:52,000 --> 00:04:54,000
Two is grounded.

74
00:04:54,000 --> 00:05:00,000
Make sure this name is exactly the same name that you have in the unit over here.

75
00:05:00,000 --> 00:05:01,000
This is very important.

76
00:05:02,000 --> 00:05:03,000
This is how it will find each other.

77
00:05:05,000 --> 00:05:06,000
Now if we go to play mode.

78
00:05:11,000 --> 00:05:12,000
And I jump.

79
00:05:13,000 --> 00:05:15,000
I can see I'm jumping and fallen.

80
00:05:16,000 --> 00:05:18,000
And if I'll run and then jump.

81
00:05:19,000 --> 00:05:20,000
Still works the same.

82
00:05:21,000 --> 00:05:22,000
Isn't it cool?

83
00:05:22,000 --> 00:05:23,000
Very cool.

84
00:05:23,000 --> 00:05:24,000
I like it.

85
00:05:24,000 --> 00:05:25,000
All right.

86
00:05:25,000 --> 00:05:26,000
That's it for this video.

87
00:05:26,000 --> 00:05:30,000
And I have a challenge for you in the next video, so let's move there.

