Physics

Table of Contents

Collision Objects, Layers and Masks discussion

All following classes inherit CollisionObject2D:

Area2D
  • can detect when objects overlap and can emit signals when bodies enter or exit
  • can override physics properties such as gravity or damping in a defined area.
  • A
StaticBody2D
  • Participates in collision detection, but does not move in response to the collision
RigidBody2D
  • Do not control a RigidBody2D directly, but instead you apply forces to it
  • You can handle collisions by connecting callback functions to signals like body_entered.
KinematicBody2D
  • A body that provides collision detection, but no physics.
  • All movement and collision response must be implemented in code.
  • There is no such thing as signals like body_entered.
  • Instead, you should use move_and_collide and investigate its return value, KinematicCollision2D.

To define collision bounds, you can add any number of CollisionShape2D or CollisionPolygon2D as child nodes.

Once you add node of those types of nodes, you can select the shapes.
Once you add node of those types of nodes, you can select the shapes.

When changing sizing the collision shape, you should always use the size handles, not the Node2D scale handles. Scaling a shape can result in unexpected collision behavior.

You can define collision layers to categorize collision objects. To exploit collision layers, you should configure collision masks for each object.

The player should collide with walls, enemies, coins, but not with itself.
The player should collide with walls, enemies, coins, but not with itself.