Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.


Inherits: Object

Inherited By: PhysicsServer2DExtension

A server interface for low-level 2D physics access.


PhysicsServer2D is the server responsible for all 2D physics. It can directly create and manipulate all physics objects:

  • A space is a self-contained world for a physics simulation. It contains bodies, areas, and joints. Its state can be queried for collision and intersection information, and several parameters of the simulation can be modified.

  • A shape is a geometric shape such as a circle, a rectangle, a capsule, or a polygon. It can be used for collision detection by adding it to a body/area, possibly with an extra transformation relative to the body/area's origin. Bodies/areas can have multiple (transformed) shapes added to them, and a single shape can be added to bodies/areas multiple times with different local transformations.

  • A body is a physical object which can be in static, kinematic, or rigid mode. Its state (such as position and velocity) can be queried and updated. A force integration callback can be set to customize the body's physics.

  • An area is a region in space which can be used to detect bodies and areas entering and exiting it. A body monitoring callback can be set to report entering/exiting body shapes, and similarly an area monitoring callback can be set. Gravity and damping can be overridden within the area by setting area parameters.

  • A joint is a constraint, either between two bodies or on one body relative to a point. Parameters such as the joint bias and the rest length of a spring joint can be adjusted.

Physics objects in PhysicsServer2D may be created and manipulated independently; they do not have to be tied to nodes in the scene tree.

Note: All the 2D physics nodes use the physics server internally. Adding a physics node to the scene tree will cause a corresponding physics object to be created in the physics server. A rigid body node registers a callback that updates the node's transform with the transform of the respective body object in the physics server (every physics update). An area node registers a callback to inform the area node about overlaps with the respective area object in the physics server. The raycast node queries the direct state of the relevant space in the physics server.



area_add_shape ( RID area, RID shape, Transform2D transform=Transform2D(1, 0, 0, 1, 0, 0), bool disabled=false )


area_attach_canvas_instance_id ( RID area, int id )


area_attach_object_instance_id ( RID area, int id )


area_clear_shapes ( RID area )


area_create ( )


area_get_canvas_instance_id ( RID area ) const


area_get_collision_layer ( RID area ) const