Physics 2D Server.
    public static class Physics2DServer

Physics 2D Server is the server responsible for all 2D physics. It can create many kinds of physics objects, but does not insert them on the node tree.

Inheritance Chain

Static Methods

    public static void AreaAddShape(RID area, RID shape, Transform2D? transform = default(Transform2D?))

Adds a shape to the area, along with a transform matrix. Shapes are usually referenced by their index, so you should track which shape has a given index.

    public static void AreaAttachObjectInstanceId(RID area, int id)

Assigns the area to a descendant of Object, so it can exist in the node tree.

    public static void AreaClearShapes(RID area)

Removes all shapes from an area. It does not delete the shapes, so they can be reassigned later.

    public static RID AreaCreate()

Creates an Area2D.

    public static int AreaGetObjectInstanceId(RID area)

Gets the instance ID of the object the area is assigned to.

    public static object AreaGetParam(RID area, AreaParameter param)

Returns an area parameter value. A list of available parameters is on the AREA_PARAM_* constants.

    public static RID AreaGetShape(RID area, int shapeIdx)

Returns the RID of the nth shape of an area.

    public static int AreaGetShapeCount(RID area)

Returns the number of shapes assigned to an area.

    public static Transform2D AreaGetShapeTransform(RID area, int shapeIdx)

Returns the transform matrix of a shape within an area.

    public static RID AreaGetSpace(RID area)

Returns the space assigned to the area.

    public static AreaSpaceOverrideMode AreaGetSpaceOverrideMode(RID area)

Returns the space override mode for the area.

    public static Transform2D AreaGetTransform(RID area)

Returns the transform matrix for an area.

    public static void AreaRemoveShape(RID area, int shapeIdx)

Removes a shape from an area. It does not delete the shape, so it can be reassigned later.

    public static void AreaSetCollisionLayer(RID area, int layer)

Assigns the area to one or many physics layers.

    public static void AreaSetCollisionMask(RID area, int mask)

Sets which physics layers the area will monitor.

    public static void AreaSetMonitorCallback(RID area, Object receiver, string method)

Sets the function to call when any body/area enters or exits the area. This callback will be called for any object interacting with the area, and takes five parameters:

1: AREA_BODY_ADDED or AREA_BODY_REMOVED, depending on whether the object entered or exited the area.

2: RID of the object that entered/exited the area.

3: Instance ID of the object that entered/exited the area.

4: The shape index of the object that entered/exited the area.

5: The shape index of the area where the object entered/exited.

    public static void AreaSetParam(RID area, AreaParameter param, object value)

Sets the value for an area parameter. A list of available parameters is on the AREA_PARAM_* constants.

    public static void AreaSetShape(RID area, int shapeIdx, RID shape)

Substitutes a given area shape by another. The old shape is selected by its index, the new one by its RID.

    public static void AreaSetShapeDisabled(RID area, int shapeIdx, bool disable)

Disables a given shape in an area.

    public static void AreaSetShapeTransform(RID area, int shapeIdx, Transform2D transform)

Sets the transform matrix for an area shape.

    public static void AreaSetSpace(RID area, RID space)

Assigns a space to the area.

    public static void AreaSetSpaceOverrideMode(RID area, AreaSpaceOverrideMode mode)

Sets the space override mode for the area. The modes are described in the constants AREA_SPACE_OVERRIDE_*.

    public static void AreaSetTransform(RID area, Transform2D transform)

Sets the transform matrix for an area.

    public static void BodyAddCollisionException(RID body, RID exceptedBody)

Adds a body to the list of bodies exempt from collisions.

    public static void BodyAddForce(RID body, Vector2 offset, Vector2 force)

Adds a positioned force to the applied force and torque. As with BodyApplyImpulse(Godot.RID, Godot.Vector2, Godot.Vector2), both the force and the offset from the body origin are in global coordinates. A force differs from an impulse in that, while the two are forces, the impulse clears itself after being applied.

    public static void BodyAddShape(RID body, RID shape, Transform2D? transform = default(Transform2D?))

Adds a shape to the body, along with a transform matrix. Shapes are usually referenced by their index, so you should track which shape has a given index.

    public static void BodyApplyImpulse(RID body, Vector2 position, Vector2 impulse)

Adds a positioned impulse to the applied force and torque. Both the force and the offset from the body origin are in global coordinates.

    public static void BodyAttachObjectInstanceId(RID body, int id)

Assigns the area to a descendant of Object, so it can exist in the node tree.

    public static void BodyClearShapes(RID body)

Removes all shapes from a body.

    public static RID BodyCreate()

Creates a physics body. The first parameter can be any value from constants BODY_MODE*, for the type of body created. Additionally, the body can be created in sleeping state to save processing time.

    public static int BodyGetCollisionLayer(RID body)

Returns the physics layer or layers a body belongs to.

    public static int BodyGetCollisionMask(RID body)

Returns the physics layer or layers a body can collide with.

    public static CCDMode BodyGetContinuousCollisionDetectionMode(RID body)

Returns the continuous collision detection mode.

    public static Physics2DDirectBodyState BodyGetDirectState(RID body)

Returns the Physics2DDirectBodyState of the body.

    public static int BodyGetMaxContactsReported(RID body)

Returns the maximum contacts that can be reported. See BodySetMaxContactsReported(Godot.RID, int).

    public static BodyMode BodyGetMode(RID body)

Returns the body mode.

    public static int BodyGetObjectInstanceId(RID body)

Gets the instance ID of the object the area is assigned to.

    public static float BodyGetParam(RID body, BodyParameter param)

Returns the value of a body parameter. A list of available parameters is on the BODY_PARAM_* constants.

    public static RID BodyGetShape(RID body, int shapeIdx)

Returns the RID of the nth shape of a body.

    public static int BodyGetShapeCount(RID body)

Returns the number of shapes assigned to a body.

    public static object BodyGetShapeMetadata(RID body, int shapeIdx)

Returns the metadata of a shape of a body.

    public static Transform2D BodyGetShapeTransform(RID body, int shapeIdx)

Returns the transform matrix of a body shape.

    public static RID BodyGetSpace(RID body)

Returns the RID of the space assigned to a body.

    public static object BodyGetState(RID body, BodyState state)

Returns a body state.

    public static bool BodyIsOmittingForceIntegration(RID body)

Returns whether a body uses a callback function to calculate its own physics (see BodySetForceIntegrationCallback(Godot.RID, Godot.Object, string, object)).

    public static void BodyRemoveCollisionException(RID body, RID exceptedBody)

Removes a body from the list of bodies exempt from collisions.

    public static void BodyRemoveShape(RID body, int shapeIdx)

Removes a shape from a body. The shape is not deleted, so it can be reused afterwards.

    public static void BodySetAxisVelocity(RID body, Vector2 axisVelocity)

Sets an axis velocity. The velocity in the given vector axis will be set as the given vector length. This is useful for jumping behavior.

    public static void BodySetCollisionLayer(RID body, int layer)

Sets the physics layer or layers a body belongs to.

    public static void BodySetCollisionMask(RID body, int mask)

Sets the physics layer or layers a body can collide with.

    public static void BodySetContinuousCollisionDetectionMode(RID body, CCDMode mode)

Sets the continuous collision detection mode from any of the CCD_MODE_* constants.

Continuous collision detection tries to predict where a moving body will collide, instead of moving it and correcting its movement if it collided.

    public static void BodySetForceIntegrationCallback(RID body, Object receiver, string method, object userdata = null)

Sets the function used to calculate physics for an object, if that object allows it (see BodySetOmitForceIntegration(Godot.RID, bool)).

    public static void BodySetMaxContactsReported(RID body, int amount)

Sets the maximum contacts to report. Bodies can keep a log of the contacts with other bodies, this is enabled by setting the maximum amount of contacts reported to a number greater than 0.

    public static void BodySetMode(RID body, BodyMode mode)

Sets the body mode, from one of the constants BODY_MODE*.

    public static void BodySetOmitForceIntegration(RID body, bool enable)

Sets whether a body uses a callback function to calculate its own physics (see BodySetForceIntegrationCallback(Godot.RID, Godot.Object, string, object)).

    public static void BodySetParam(RID body, BodyParameter param, float value)

Sets a body parameter. A list of available parameters is on the BODY_PARAM_* constants.

    public static void BodySetShape(RID body, int shapeIdx, RID shape)

Substitutes a given body shape by another. The old shape is selected by its index, the new one by its RID.

    public static void BodySetShapeAsOneWayCollision(RID body, int shapeIdx, bool enable)

Enables one way collision on body if enable is true.

    public static void BodySetShapeDisabled(RID body, int shapeIdx, bool disable)

Disables shape in body if disable is true.

    public static void BodySetShapeMetadata(RID body, int shapeIdx, object metadata)

Sets metadata of a shape within a body. This metadata is different from Object.SetMeta(string, object), and can be retrieved on shape queries.

    public static void BodySetShapeTransform(RID body, int shapeIdx, Transform2D transform)

Sets the transform matrix for a body shape.

    public static void BodySetSpace(RID body, RID space)

Assigns a space to the body (see SpaceCreate()).

    public static void BodySetState(RID body, BodyState state, object value)

Sets a body state (see BODY_STATE* constants).

    public static bool BodyTestMotion(RID body, Transform2D from, Vector2 motion, float margin = 0.08f, Physics2DTestMotionResult result = null)

Returns whether a body can move from a given point in a given direction. Apart from the boolean return value, a Physics2DTestMotionResult can be passed to return additional information in.

    public static RID CapsuleShapeCreate()

    public static RID CircleShapeCreate()

    public static RID ConcavePolygonShapeCreate()

    public static RID ConvexPolygonShapeCreate()

    public static RID DampedSpringJointCreate(Vector2 anchorA, Vector2 anchorB, RID bodyA, RID bodyB = null)

Creates a damped spring joint between two bodies. If not specified, the second body is assumed to be the joint itself.

    public static float DampedStringJointGetParam(RID joint, DampedStringParam param)

Returns the value of a damped spring joint parameter.

    public static void DampedStringJointSetParam(RID joint, DampedStringParam param, float value)

Sets a damped spring joint parameter. Parameters are explained in the DAMPED_STRING* constants.

    public static void FreeRid(RID rid)

Destroys any of the objects created by Physics2DServer. If the RID passed is not one of the objects that can be created by Physics2DServer, an error will be sent to the console.

    public static int GetProcessInfo(ProcessInfo processInfo)

Returns information about the current state of the 2D physics engine. The states are listed under the INFO_* constants.

    public static RID GrooveJointCreate(Vector2 groove1A, Vector2 groove2A, Vector2 anchorB, RID bodyA = null, RID bodyB = null)

Creates a groove joint between two bodies. If not specified, the bodyies are assumed to be the joint itself.

    public static float JointGetParam(RID joint, JointParam param)

Returns the value of a joint parameter.

    public static JointType JointGetType(RID joint)

Returns the type of a joint (see JOINT_* constants).

    public static void JointSetParam(RID joint, JointParam param, float value)

Sets a joint parameter. Parameters are explained in the JOINT_PARAM* constants.

    public static RID LineShapeCreate()

    public static RID PinJointCreate(Vector2 anchor, RID bodyA, RID bodyB = null)

Creates a pin joint between two bodies. If not specified, the second body is assumed to be the joint itself.

    public static RID RayShapeCreate()

    public static RID RectangleShapeCreate()

    public static RID SegmentShapeCreate()

    public static void SetActive(bool active)

Activates or deactivates the 2D physics engine.

    public static object ShapeGetData(RID shape)

Returns the shape data.

    public static ShapeType ShapeGetType(RID shape)

Returns the type of shape (see SHAPE_* constants).

    public static void ShapeSetData(RID shape, object data)

Sets the shape data that defines its shape and size. The data to be passed depends on the kind of shape created ShapeGetType(Godot.RID).

    public static RID SpaceCreate()

Creates a space. A space is a collection of parameters for the physics engine that can be assigned to an area or a body. It can be assigned to an area with AreaSetSpace(Godot.RID, Godot.RID), or to a body with BodySetSpace(Godot.RID, Godot.RID).

    public static Physics2DDirectSpaceState SpaceGetDirectState(RID space)

Returns the state of a space, a Physics2DDirectSpaceState. This object can be used to make collision/intersection queries.

    public static float SpaceGetParam(RID space, SpaceParameter param)

Returns the value of a space parameter.

    public static bool SpaceIsActive(RID space)

Returns whether the space is active.

    public static void SpaceSetActive(RID space, bool active)

Marks a space as active. It will not have an effect, unless it is assigned to an area or body.

    public static void SpaceSetParam(RID space, SpaceParameter param, float value)

Sets the value for a space parameter. A list of available parameters is on the SPACE_PARAM_* constants.

Inner Types

AreaBodyStatus

Name Value Description
Added 0 The value of the first parameter and area callback function receives, when an object enters one of its shapes.
Removed 1 The value of the first parameter and area callback function receives, when an object exits one of its shapes.

AreaParameter

Name Value Description
Gravity 0 Constant to set/get gravity strength in an area.
GravityVector 1 Constant to set/get gravity vector/center in an area.
GravityIsPoint 2 Constant to set/get whether the gravity vector of an area is a direction, or a center point.
GravityDistanceScale 3 Constant to set/get the falloff factor for point gravity of an area. The greater this value is, the faster the strength of gravity decreases with the square of distance.
GravityPointAttenuation 4 This constant was used to set/get the falloff factor for point gravity. It has been superseded by AREA_PARAM_GRAVITY_DISTANCE_SCALE.
LinearDamp 5 Constant to set/get the linear dampening factor of an area.
AngularDamp 6 Constant to set/get the angular dampening factor of an area.
Priority 7 Constant to set/get the priority (order of processing) of an area.

AreaSpaceOverrideMode

Name Value Description
Disabled 0 This area does not affect gravity/damp. These are generally areas that exist only to detect collisions, and objects entering or exiting them.
Combine 1 This area adds its gravity/damp values to whatever has been calculated so far. This way, many overlapping areas can combine their physics to make interesting effects.
CombineReplace 2 This area adds its gravity/damp values to whatever has been calculated so far. Then stops taking into account the rest of the areas, even the default one.
Replace 3 This area replaces any gravity/damp, even the default one, and stops taking into account the rest of the areas.
ReplaceCombine 4 This area replaces any gravity/damp calculated so far, but keeps calculating the rest of the areas, down to the default one.

BodyMode

Name Value Description
Static 0 Constant for static bodies.
Kinematic 1 Constant for kinematic bodies.
Rigid 2 Constant for rigid bodies.
Character 3 Constant for rigid bodies in character mode. In this mode, a body can not rotate, and only its linear velocity is affected by physics.

BodyParameter

Name Value Description
Bounce 0 Constant to set/get a body’s bounce factor.
Friction 1 Constant to set/get a body’s friction.
Mass 2 Constant to set/get a body’s mass.
Inertia 3 Constant to set/get a body’s inertia.
GravityScale 4 Constant to set/get a body’s gravity multiplier.
LinearDamp 5 Constant to set/get a body’s linear dampening factor.
AngularDamp 6 Constant to set/get a body’s angular dampening factor.
Max 7 This is the last ID for body parameters. Any attempt to set this property is ignored. Any attempt to get it returns 0.

BodyState

Name Value Description
Transform 0 Constant to set/get the current transform matrix of the body.
LinearVelocity 1 Constant to set/get the current linear velocity of the body.
AngularVelocity 2 Constant to set/get the current angular velocity of the body.
Sleeping 3 Constant to sleep/wake up a body, or to get whether it is sleeping.
CanSleep 4 Constant to set/get whether the body can sleep.

CCDMode

Name Value Description
Disabled 0 Disables continuous collision detection. This is the fastest way to detect body collisions, but can miss small, fast-moving objects.
CastRay 1 Enables continuous collision detection by raycasting. It is faster than shapecasting, but less precise.
CastShape 2 Enables continuous collision detection by shapecasting. It is the slowest CCD method, and the most precise.

DampedStringParam

Name Value Description
RestLength 0 Set the resting length of the spring joint. The joint will always try to go to back this length when pulled apart.
Stiffness 1 Set the stiffness of the spring joint. The joint applies a force equal to the stiffness times the distance from its resting length.
Damping 2 Set the damping ratio of the spring joint. A value of 0 indicates an undamped spring, while 1 causes the system to reach equilibrium as fast as possible (critical damping).

JointParam

Name Value Description
Bias 0  
MaxBias 1  
MaxForce 2  

JointType

Name Value Description
Pin 0 Constant to create pin joints.
Groove 1 Constant to create groove joints.
DampedSpring 2 Constant to create damped spring joints.

ProcessInfo

Name Value Description
ActiveObjects 0 Constant to get the number of objects that are not sleeping.
CollisionPairs 1 Constant to get the number of possible collisions.
IslandCount 2 Constant to get the number of space regions where a collision could occur.

ShapeType

Name Value Description
Line 0 This is the constant for creating line shapes. A line shape is an infinite line with an origin point, and a normal. Thus, it can be used for front/behind checks.
Ray 1  
Segment 2 This is the constant for creating segment shapes. A segment shape is a line from a point A to a point B. It can be checked for intersections.
Circle 3 This is the constant for creating circle shapes. A circle shape only has a radius. It can be used for intersections and inside/outside checks.
Rectangle 4 This is the constant for creating rectangle shapes. A rectangle shape is defined by a width and a height. It can be used for intersections and inside/outside checks.
Capsule 5 This is the constant for creating capsule shapes. A capsule shape is defined by a radius and a length. It can be used for intersections and inside/outside checks.
ConvexPolygon 6 This is the constant for creating convex polygon shapes. A polygon is defined by a list of points. It can be used for intersections and inside/outside checks. Unlike the method [method CollisionPolygon2D.set_polygon], polygons modified with [method shape_set_data] do not verify that the points supplied form is a convex polygon.
ConcavePolygon 7 This is the constant for creating concave polygon shapes. A polygon is defined by a list of points. It can be used for intersections checks, but not for inside/outside checks.
Custom 8 This constant is used internally by the engine. Any attempt to create this kind of shape results in an error.

SpaceParameter

Name Value Description
ContactRecycleRadius 0 Constant to set/get the maximum distance a pair of bodies has to move before their collision status has to be recalculated.
ContactMaxSeparation 1 Constant to set/get the maximum distance a shape can be from another before they are considered separated.
BodyMaxAllowedPenetration 2 Constant to set/get the maximum distance a shape can penetrate another shape before it is considered a collision.
BodyLinearVelocitySleepThreshold 3 Constant to set/get the threshold linear velocity of activity. A body marked as potentially inactive for both linear and angular velocity will be put to sleep after the time given.
BodyAngularVelocitySleepThreshold 4 Constant to set/get the threshold angular velocity of activity. A body marked as potentially inactive for both linear and angular velocity will be put to sleep after the time given.
BodyTimeToSleep 5 Constant to set/get the maximum time of activity. A body marked as potentially inactive for both linear and angular velocity will be put to sleep after this time.
ConstraintDefaultBias 6 Constant to set/get the default solver bias for all physics constraints. A solver bias is a factor controlling how much two objects “rebound”, after violating a constraint, to avoid leaving them in that state because of numerical imprecision.
Tags: