Hello, guys.
In this video, we're going to talk about collisions and rigid bodies.
And these two components are very important and basically essential for game development.
All right.
We're going to begin with the rigid body.
So I want to select my square, the first one.
Let's make his scale one and one and place it somewhere here.
And then we're going to click add component and find rigid body 2D, because we work into this space.
All right.
So now it has rigid body.
Now physics and gravity is applied to this object.
Now, if I go to play mode and before I do that, let me change aspect here to 16 to 9 like that, right?
Because this is what most of the resolutions are on, the computers and phones and so on.
Now watch this.
I go to play mode and my square begin to fall because now properties of the physics is applied to this
object.
Now let's take a look at the rigid body.
I'm going to close these two.
There are body type dynamic, kinematic and static and dynamic means physics applied to this rigid body
and it can be moved.
Then there is a kinematic and that means it can be moved, but physics is not applied to the object.
So now if I select it, you can see there is no gravity, but still it can be moved and static means
it cannot be moved at all.
So when we run the game, even if you apply some force to it, it won't be moved.
It will be static.
So.
Yeah, that's how it is.
Let's change it back to dynamic and see.
There is a material physics material and we're going to use it later, so I'll just leave it for now.
Some other important settings here is the mass of the body Drag and gravity scale.
Mass is used to define what object is heavier compared to others.
And later on we're going to use some examples to see that.
For now, let's just leave it like that drag use basically as an air resistance.
So if you have lots of drugs on the object, it will fall slower, for example.
Well, we can compare it right now.
Look how it falls.
And then if I move it up and said, Drag over five, let's say look now.
False.
Much slower.
You can see that, right?
And if I change it back to zero.
False faster.
Then there is some other settings we don't want to mess with right now, but we want to open constraints
and see what's here.
Here you can freeze position of the object and freeze rotation, which can be useful in some cases.
Later on we're going to use it with a character and I want to show you what it does.
But before we do that, let's talk about colliders.
Let's click add component of the Box Collider to D, and now we can see there is a collider on this
object and you should know the shape of the object defined by the collider, not the look of it, not
the sprite.
If I take this square over here and add the box collider to it and we don't need it by the collider
is enough and hit play something like this.
Look.
It's going to fall on the top.
And if I, let's say, place it like this.
Oh, wait a second.
Wait a second.
We need to add another collider here.
Box Collider to the.
Let's say I place them like this and take my first square and place them like this.
Right?
So clearer we can see that Sprite is not reaching the platform on the left, but there is a collider
that does that.
So that's why it doesn't fall.
Shape is defined by the collider, not the object.
If I go here to the size and set one and one.
And offset zero zero.
We can see it felt true because Collider is not.
Where is it?
All right.
So far.
Let me do it again.
Zero zero and one.
And one.
So now we can see it does not reach the platform and probably it will fall through.
Neglect me now.
But if we select this object and freeze rotation on the Z, look what's going to happen.
It doesn't fall because rotation is blocked.
Very simple.
Yeah.
Boom.
And already you can make some cool stuff with it, For example.
Let me delete this one.
Use this one.
Make it bigger with a tt w to move and I want to add rigid body to it region by the two D.
I want to make it dynamic, but I want to freeze position on the X and on the y.
But I want to keep the rotation.
And this one I'll change back to square.
Now look what's going to happen on.
You can make cool platforms as false and that's how it is.
Collider can be used in different ways and we're going to do that later as well and worry about it like
everything comes at the right time.
And before I finish this video, I want to say something important.
Listen to me carefully.
This is how it works.
You just basically take an object, you create an empty object, and let's say it will be your player.
All right, then you give it a Sprite renderer to define a look of it and.
This one doesn't have any.
You don't need to follow me now.
It's just an example.
So now this one has a picture.
Very cool.
Right.
Then I want to make it full so it behaves like an object.
You add another component of rigid body and then you give it a collider.
And basically you have your player here who can run and fold.
So this is how it is.
And then you add some different components to behave in different like if you want to make an animation
for the player, you add animator and then you make animations.
And this is very easy.
You just need to understand how it works and get used to components and know what component you can
use when to make the task you need.
All right.
Very simple.
Very cool.
All right.
Let's go to the next video and create the player properly, and I'll delete this one.