ThreeAmmo

# Godot Body2D node

In real life, we walk around. We bump into each other, we bump into footballs and we bump into light posts then fall and bump into the ground under the force of gravity. Typical human experience. We like to relive this experience in video games.

The physics of these situations are then described by two things:

• Physical contact (collisions),
• Action at a distance (forces, spooky or otherwise).

Collisions happen when objects come into contact. Forces act on objects depending on their position, regardless of proximity. We also encounter ghosts, these are objects that we cannot collide with, we usually pass through great-grand-auntie with no detectable effect, and they do not obey the force laws of the world.

Objects that interact with the world according to the two ways mentioned above are described in Godot as PhysicsBody2D nodes. Anything (node) that ends with Body2D is going to inherit all the properties of the PhysicsBody2D node.

When we hit a light post, or a wall, or a building, these objects don’t react to us colliding with them. They also don’t respond to gravity or other forces. These are StaticBody2D nodes. They remain, well, static. But we can’t pass through them, we still collide with them. We get affected by them, but we cannot affect them.

We kick a football and it moves. That’s an object that moves (more precisely, changes its state of motion) only when acted upon by an external force, it cannot move on its own. In game, this force is provided by the collision between the player and the ball. Objects that can be moved through application of in-game physics are RigidBody2D nodes in Godot. The in-game physics are defined by the developer, something analogous to $$F=ma$$ and collisions.

When we decide to walk around, this motion is not caused by external, visible forces from the outside world. Same with cars, they really move because of the engine inside but that is internal to the car, it’s not an outside force. In Godot, these objects (people walking and cars moving) can then be thought of as agents having free will, their motion is not described by the dynamical law $$F=ma$$. When an agent decides to move, this free-will motion is not dynamical in that sense, it’s kinematical. We can only describe it in terms of change in position, but not the causes of this change. This is the KinematicBody2D node in the Godot engine. The free will (internal forces) are provided by the player’s press on the control buttons or a behaviour code. These objects can be made to obey physics but this has to be coded, they do not obey general world physics like RigidBody2D nodes.

I’m talking about 2D nodes only because I didn’t even touch the 3D engine, but I imagine the ideas would be similar.

Tags: #godot