1
00:00:00,000 --> 00:00:01,000
Hello, guys.

2
00:00:01,000 --> 00:00:04,000
In this video, we're going to talk about collisions and rigid bodies.

3
00:00:04,000 --> 00:00:09,000
And these two components are very important and basically essential for game development.

4
00:00:09,000 --> 00:00:10,000
All right.

5
00:00:10,000 --> 00:00:12,000
We're going to begin with the rigid body.

6
00:00:12,000 --> 00:00:15,000
So I want to select my square, the first one.

7
00:00:16,000 --> 00:00:20,000
Let's make his scale one and one and place it somewhere here.

8
00:00:20,000 --> 00:00:27,000
And then we're going to click add component and find rigid body 2D, because we work into this space.

9
00:00:27,000 --> 00:00:28,000
All right.

10
00:00:29,000 --> 00:00:31,000
So now it has rigid body.

11
00:00:31,000 --> 00:00:36,000
Now physics and gravity is applied to this object.

12
00:00:36,000 --> 00:00:43,000
Now, if I go to play mode and before I do that, let me change aspect here to 16 to 9 like that, right?

13
00:00:43,000 --> 00:00:48,000
Because this is what most of the resolutions are on, the computers and phones and so on.

14
00:00:48,000 --> 00:00:49,000
Now watch this.

15
00:00:49,000 --> 00:00:55,000
I go to play mode and my square begin to fall because now properties of the physics is applied to this

16
00:00:55,000 --> 00:00:55,000
object.

17
00:00:55,000 --> 00:00:58,000
Now let's take a look at the rigid body.

18
00:00:58,000 --> 00:00:59,000
I'm going to close these two.

19
00:00:59,000 --> 00:01:08,000
There are body type dynamic, kinematic and static and dynamic means physics applied to this rigid body

20
00:01:08,000 --> 00:01:09,000
and it can be moved.

21
00:01:09,000 --> 00:01:16,000
Then there is a kinematic and that means it can be moved, but physics is not applied to the object.

22
00:01:16,000 --> 00:01:22,000
So now if I select it, you can see there is no gravity, but still it can be moved and static means

23
00:01:22,000 --> 00:01:24,000
it cannot be moved at all.

24
00:01:24,000 --> 00:01:29,000
So when we run the game, even if you apply some force to it, it won't be moved.

25
00:01:29,000 --> 00:01:31,000
It will be static.

26
00:01:31,000 --> 00:01:31,000
So.

27
00:01:32,000 --> 00:01:34,000
Yeah, that's how it is.

28
00:01:34,000 --> 00:01:36,000
Let's change it back to dynamic and see.

29
00:01:36,000 --> 00:01:41,000
There is a material physics material and we're going to use it later, so I'll just leave it for now.

30
00:01:41,000 --> 00:01:47,000
Some other important settings here is the mass of the body Drag and gravity scale.

31
00:01:47,000 --> 00:01:52,000
Mass is used to define what object is heavier compared to others.

32
00:01:52,000 --> 00:01:55,000
And later on we're going to use some examples to see that.

33
00:01:55,000 --> 00:02:00,000
For now, let's just leave it like that drag use basically as an air resistance.

34
00:02:00,000 --> 00:02:04,000
So if you have lots of drugs on the object, it will fall slower, for example.

35
00:02:04,000 --> 00:02:06,000
Well, we can compare it right now.

36
00:02:07,000 --> 00:02:08,000
Look how it falls.

37
00:02:08,000 --> 00:02:13,000
And then if I move it up and said, Drag over five, let's say look now.

38
00:02:14,000 --> 00:02:15,000
False.

39
00:02:15,000 --> 00:02:15,000
Much slower.

40
00:02:15,000 --> 00:02:16,000
You can see that, right?

41
00:02:16,000 --> 00:02:18,000
And if I change it back to zero.

42
00:02:19,000 --> 00:02:20,000
False faster.

43
00:02:20,000 --> 00:02:26,000
Then there is some other settings we don't want to mess with right now, but we want to open constraints

44
00:02:26,000 --> 00:02:28,000
and see what's here.

45
00:02:28,000 --> 00:02:33,000
Here you can freeze position of the object and freeze rotation, which can be useful in some cases.

46
00:02:33,000 --> 00:02:36,000
Later on we're going to use it with a character and I want to show you what it does.

47
00:02:36,000 --> 00:02:39,000
But before we do that, let's talk about colliders.

48
00:02:39,000 --> 00:02:47,000
Let's click add component of the Box Collider to D, and now we can see there is a collider on this

49
00:02:47,000 --> 00:02:53,000
object and you should know the shape of the object defined by the collider, not the look of it, not

50
00:02:53,000 --> 00:02:54,000
the sprite.

51
00:02:54,000 --> 00:03:00,000
If I take this square over here and add the box collider to it and we don't need it by the collider

52
00:03:00,000 --> 00:03:03,000
is enough and hit play something like this.

53
00:03:03,000 --> 00:03:04,000
Look.

54
00:03:07,000 --> 00:03:09,000
It's going to fall on the top.

55
00:03:09,000 --> 00:03:14,000
And if I, let's say, place it like this.

56
00:03:16,000 --> 00:03:17,000
Oh, wait a second.

57
00:03:18,000 --> 00:03:18,000
Wait a second.

58
00:03:18,000 --> 00:03:20,000
We need to add another collider here.

59
00:03:21,000 --> 00:03:22,000
Box Collider to the.

60
00:03:24,000 --> 00:03:29,000
Let's say I place them like this and take my first square and place them like this.

61
00:03:29,000 --> 00:03:29,000
Right?

62
00:03:29,000 --> 00:03:35,000
So clearer we can see that Sprite is not reaching the platform on the left, but there is a collider

63
00:03:35,000 --> 00:03:36,000
that does that.

64
00:03:36,000 --> 00:03:38,000
So that's why it doesn't fall.

65
00:03:38,000 --> 00:03:41,000
Shape is defined by the collider, not the object.

66
00:03:41,000 --> 00:03:44,000
If I go here to the size and set one and one.

67
00:03:46,000 --> 00:03:47,000
And offset zero zero.

68
00:03:47,000 --> 00:03:50,000
We can see it felt true because Collider is not.

69
00:03:50,000 --> 00:03:51,000
Where is it?

70
00:03:51,000 --> 00:03:51,000
All right.

71
00:03:52,000 --> 00:03:52,000
So far.

72
00:03:54,000 --> 00:03:55,000
Let me do it again.

73
00:03:57,000 --> 00:03:58,000
Zero zero and one.

74
00:03:58,000 --> 00:03:59,000
And one.

75
00:03:59,000 --> 00:04:05,000
So now we can see it does not reach the platform and probably it will fall through.

76
00:04:07,000 --> 00:04:08,000
Neglect me now.

77
00:04:09,000 --> 00:04:14,000
But if we select this object and freeze rotation on the Z, look what's going to happen.

78
00:04:14,000 --> 00:04:17,000
It doesn't fall because rotation is blocked.

79
00:04:17,000 --> 00:04:18,000
Very simple.

80
00:04:18,000 --> 00:04:18,000
Yeah.

81
00:04:20,000 --> 00:04:20,000
Boom.

82
00:04:21,000 --> 00:04:25,000
And already you can make some cool stuff with it, For example.

83
00:04:25,000 --> 00:04:27,000
Let me delete this one.

84
00:04:27,000 --> 00:04:28,000
Use this one.

85
00:04:28,000 --> 00:04:35,000
Make it bigger with a tt w to move and I want to add rigid body to it region by the two D.

86
00:04:35,000 --> 00:04:40,000
I want to make it dynamic, but I want to freeze position on the X and on the y.

87
00:04:40,000 --> 00:04:42,000
But I want to keep the rotation.

88
00:04:42,000 --> 00:04:44,000
And this one I'll change back to square.

89
00:04:44,000 --> 00:04:46,000
Now look what's going to happen on.

90
00:04:47,000 --> 00:04:51,000
You can make cool platforms as false and that's how it is.

91
00:04:51,000 --> 00:04:56,000
Collider can be used in different ways and we're going to do that later as well and worry about it like

92
00:04:56,000 --> 00:04:58,000
everything comes at the right time.

93
00:04:58,000 --> 00:05:01,000
And before I finish this video, I want to say something important.

94
00:05:01,000 --> 00:05:02,000
Listen to me carefully.

95
00:05:02,000 --> 00:05:03,000
This is how it works.

96
00:05:03,000 --> 00:05:09,000
You just basically take an object, you create an empty object, and let's say it will be your player.

97
00:05:09,000 --> 00:05:15,000
All right, then you give it a Sprite renderer to define a look of it and.

98
00:05:17,000 --> 00:05:18,000
This one doesn't have any.

99
00:05:18,000 --> 00:05:19,000
You don't need to follow me now.

100
00:05:19,000 --> 00:05:20,000
It's just an example.

101
00:05:20,000 --> 00:05:23,000
So now this one has a picture.

102
00:05:23,000 --> 00:05:23,000
Very cool.

103
00:05:23,000 --> 00:05:24,000
Right.

104
00:05:24,000 --> 00:05:28,000
Then I want to make it full so it behaves like an object.

105
00:05:28,000 --> 00:05:31,000
You add another component of rigid body and then you give it a collider.

106
00:05:31,000 --> 00:05:35,000
And basically you have your player here who can run and fold.

107
00:05:36,000 --> 00:05:37,000
So this is how it is.

108
00:05:37,000 --> 00:05:42,000
And then you add some different components to behave in different like if you want to make an animation

109
00:05:42,000 --> 00:05:46,000
for the player, you add animator and then you make animations.

110
00:05:46,000 --> 00:05:47,000
And this is very easy.

111
00:05:47,000 --> 00:05:53,000
You just need to understand how it works and get used to components and know what component you can

112
00:05:53,000 --> 00:05:57,000
use when to make the task you need.

113
00:05:57,000 --> 00:05:57,000
All right.

114
00:05:57,000 --> 00:05:58,000
Very simple.

115
00:05:58,000 --> 00:05:59,000
Very cool.

116
00:05:59,000 --> 00:06:00,000
All right.

117
00:06:00,000 --> 00:06:05,000
Let's go to the next video and create the player properly, and I'll delete this one.

