Hello and welcome to another episode on the Godot basics tutorial series. In this episode we will be taking a look at physics body 2D. Physics Body 2D is the bass class for all objects that are affected by physics and 2D space. If you want collisions where objects don't intersect by default. Think of body 2D Node. Godot gives us three different types of nodes. We are able to use and decode doe application. They are the static body 2D the rigid body 2D and Kinimatic body to the static body 2D the default node when dealing with non moving objects. One
One way to think about static bodies is that you use them on objects you would like to be statically placed in your game world. These would include game objects such as floors walls ceilings pillars basically anything that you don't want to move. Basically you'll use this on any object where you never have the intention of utilizing physics based reaction. This does not mean it can't affect other body to the objects. For example static body 2D does come with methods such as constant linear velocity and constant angular velocity which allows your static body 2d to have certain effects on objects that collide with them. Next
Next on the list is rigid body to do you use rigid body 2D when you want to have physics forces applied to your game object. Think of gravity friction any kind of object where you wish to apply Newton's third law. Keep in mind that rigid body 2D is not meant to be used for user controlled game objects. Basically don't use rigid body 2D on your main playable character. If you want your player object to be affected by other physics body objects or affect other physics body objects you will use the cinematic body to denote basically the way.
Kinimatic body to works as if you move towards a static body. Your player will be unable to move. However, when you're a Kinimatic body 2D moves towards a rigid body. You would like that rigid body to react to your main player which again has Kinimatic body 2D and have it affected by physics in this case it would be a force applied to your rigid body by your Kinimatic Body. Kinimatic Body Node comes with two methods that allow us to move our game object.
That would be the moving collide method and the move and slide method. Keep in mind that both take in a vector to value as its first argument. You use the moving collide method when you would like your game object to stop moving after a collision has been internally detected. However in most cases you would like to have your game object move. For example if you're falling down and running at the same time you would like your game object to just keep moving along rather than stopping after it hits the ground.
In these rare cases where you would like to move for example on a slope or a hill you would most likely opt out for the other method instead. If you were to use the move and slide method your game object will stop moving in the direction of the blocked path. That's where the name comes from. Instead of stopping you slide. For example if you're moving southwest basically at a diagonal and there happens to be a floor your game object will not move south anymore instead it will just move west at a reduced speed if you are still or rather if you're a game object is still having a momentum applied to it in the south west direction.
One thing to keep in mind is that move in slide and moving collide are almost the same exact thing. The only behavior that differentiates the two is that moving collide will stop its movement after it collides with the game object and move and slide will continue to move along an axis that is not block to your can somatic body to day. As a matter of fact you can get the same behavior from moving collide by adding an if statement and telling it to ignore going in one direction and just continue along an access. That
That is not blocked or rather an axis that has no game object that is blocking your can Imagic body to the movement. So again to recap you'll want to use static body 2D node on game objects that you have no intention of moving. You will want to use rigid body 2D on game objects where you wish your character player can interact and collide with and apply some type of physics based. In this case force applied to your rigid body to the game object. And lastly you reserve kinetic body 2D for any main playable character that your game provides.
In this case your human player. Well that's all I have for you in this episode. Thank you so much for joining me. Q For clicking the like button and thank you for clicking the Subscribe button. If you have any questions or comments please feel free to leave them in the comments section down below. I look forward to seeing you in the next episode. Have an amazing day.