Table of Contents

Class PhysicsServer2DInstance

Namespace
Godot
Assembly
GodotSharp.dll

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.

[GodotClassName("PhysicsServer2D")]
public class PhysicsServer2DInstance : GodotObject, IDisposable
Inheritance
PhysicsServer2DInstance
Implements
Derived
Inherited Members

Methods

AreaAddShape(Rid, Rid, Transform2D?, bool)

Adds a shape to the area, with the given local transform. The shape (together with its transform and disabled properties) is added to an array of shapes, and the shapes of an area are usually referenced by their index in this array.

public void AreaAddShape(Rid area, Rid shape, Transform2D? transform = null, bool disabled = false)

Parameters

area Rid
shape Rid
transform Transform2D?

If the parameter is null, then the default value is Transform2D.Identity.

disabled bool

AreaAttachCanvasInstanceId(Rid, ulong)

Attaches the ObjectID of a canvas to the area. Use GetInstanceId() to get the ObjectID of a CanvasLayer.

public void AreaAttachCanvasInstanceId(Rid area, ulong id)

Parameters

area Rid
id ulong

AreaAttachObjectInstanceId(Rid, ulong)

Attaches the ObjectID of an GodotObject to the area. Use GetInstanceId() to get the ObjectID of a CollisionObject2D.

public void AreaAttachObjectInstanceId(Rid area, ulong id)

Parameters

area Rid
id ulong

AreaClearShapes(Rid)

Removes all shapes from the area. This does not delete the shapes themselves, so they can continue to be used elsewhere or added back later.

public void AreaClearShapes(Rid area)

Parameters

area Rid

AreaCreate()

Creates a 2D area object in the physics server, and returns the Rid that identifies it. Use AreaAddShape(Rid, Rid, Transform2D?, bool) to add shapes to it, use AreaSetTransform(Rid, Transform2D) to set its transform, and use AreaSetSpace(Rid, Rid) to add the area to a space.

public Rid AreaCreate()

Returns

Rid

AreaGetCanvasInstanceId(Rid)

Returns the ObjectID of the canvas attached to the area. Use @GlobalScope.instance_from_id to retrieve a CanvasLayer from a nonzero ObjectID.

public ulong AreaGetCanvasInstanceId(Rid area)

Parameters

area Rid

Returns

ulong

AreaGetCollisionLayer(Rid)

Returns the physics layer or layers the area belongs to, as a bitmask.

public uint AreaGetCollisionLayer(Rid area)

Parameters

area Rid

Returns

uint

AreaGetCollisionMask(Rid)

Returns the physics layer or layers the area can contact with, as a bitmask.

public uint AreaGetCollisionMask(Rid area)

Parameters

area Rid

Returns

uint

AreaGetObjectInstanceId(Rid)

Returns the ObjectID attached to the area. Use @GlobalScope.instance_from_id to retrieve an GodotObject from a nonzero ObjectID.

public ulong AreaGetObjectInstanceId(Rid area)

Parameters

area Rid

Returns

ulong

AreaGetParam(Rid, AreaParameter)

Returns the value of the given area parameter. See PhysicsServer2D.AreaParameter for the list of available parameters.

public Variant AreaGetParam(Rid area, PhysicsServer2D.AreaParameter param)

Parameters

area Rid
param PhysicsServer2D.AreaParameter

Returns

Variant

AreaGetShape(Rid, int)

Returns the Rid of the shape with the given index in the area's array of shapes.

public Rid AreaGetShape(Rid area, int shapeIdx)

Parameters

area Rid
shapeIdx int

Returns

Rid

AreaGetShapeCount(Rid)

Returns the number of shapes added to the area.

public int AreaGetShapeCount(Rid area)

Parameters

area Rid

Returns

int

AreaGetShapeTransform(Rid, int)

Returns the local transform matrix of the shape with the given index in the area's array of shapes.

public Transform2D AreaGetShapeTransform(Rid area, int shapeIdx)

Parameters

area Rid
shapeIdx int

Returns

Transform2D

AreaGetSpace(Rid)

Returns the Rid of the space assigned to the area. Returns an empty Rid if no space is assigned.

public Rid AreaGetSpace(Rid area)

Parameters

area Rid

Returns

Rid

AreaGetTransform(Rid)

Returns the transform matrix of the area.

public Transform2D AreaGetTransform(Rid area)

Parameters

area Rid

Returns

Transform2D

AreaRemoveShape(Rid, int)

Removes the shape with the given index from the area's array of shapes. The shape itself is not deleted, so it can continue to be used elsewhere or added back later. As a result of this operation, the area's shapes which used to have indices higher than shapeIdx will have their index decreased by one.

public void AreaRemoveShape(Rid area, int shapeIdx)

Parameters

area Rid
shapeIdx int

AreaSetAreaMonitorCallback(Rid, Callable)

Sets the area's area monitor callback. This callback will be called when any other (shape of an) area enters or exits (a shape of) the given area, and must take the following five parameters:

1. an integer status: either Added or Removed depending on whether the other area's shape entered or exited the area,

2. an Ridarea_rid: the Rid of the other area that entered or exited the area,

3. an integer instance_id: the ObjectID attached to the other area,

4. an integer area_shape_idx: the index of the shape of the other area that entered or exited the area,

5. an integer self_shape_idx: the index of the shape of the area where the other area entered or exited.

By counting (or keeping track of) the shapes that enter and exit, it can be determined if an area (with all its shapes) is entering for the first time or exiting for the last time.

public void AreaSetAreaMonitorCallback(Rid area, Callable callback)

Parameters

area Rid
callback Callable

AreaSetCollisionLayer(Rid, uint)

Assigns the area to one or many physics layers, via a bitmask.

public void AreaSetCollisionLayer(Rid area, uint layer)

Parameters

area Rid
layer uint

AreaSetCollisionMask(Rid, uint)

Sets which physics layers the area will monitor, via a bitmask.

public void AreaSetCollisionMask(Rid area, uint mask)

Parameters

area Rid
mask uint

AreaSetMonitorCallback(Rid, Callable)

Sets the area's body monitor callback. This callback will be called when any other (shape of a) body enters or exits (a shape of) the given area, and must take the following five parameters:

1. an integer status: either Added or Removed depending on whether the other body shape entered or exited the area,

2. an Ridbody_rid: the Rid of the body that entered or exited the area,

3. an integer instance_id: the ObjectID attached to the body,

4. an integer body_shape_idx: the index of the shape of the body that entered or exited the area,

5. an integer self_shape_idx: the index of the shape of the area where the body entered or exited.

By counting (or keeping track of) the shapes that enter and exit, it can be determined if a body (with all its shapes) is entering for the first time or exiting for the last time.

public void AreaSetMonitorCallback(Rid area, Callable callback)

Parameters

area Rid
callback Callable

AreaSetMonitorable(Rid, bool)

Sets whether the area is monitorable or not. If monitorable is true, the area monitoring callback of other areas will be called when this area enters or exits them.

public void AreaSetMonitorable(Rid area, bool monitorable)

Parameters

area Rid
monitorable bool

AreaSetParam(Rid, AreaParameter, Variant)

Sets the value of the given area parameter. See PhysicsServer2D.AreaParameter for the list of available parameters.

public void AreaSetParam(Rid area, PhysicsServer2D.AreaParameter param, Variant value)

Parameters

area Rid
param PhysicsServer2D.AreaParameter
value Variant

AreaSetShape(Rid, int, Rid)

Replaces the area's shape at the given index by another shape, while not affecting the transform and disabled properties at the same index.

public void AreaSetShape(Rid area, int shapeIdx, Rid shape)

Parameters

area Rid
shapeIdx int
shape Rid

AreaSetShapeDisabled(Rid, int, bool)

Sets the disabled property of the area's shape with the given index. If disabled is true, then the shape will not detect any other shapes entering or exiting it.

public void AreaSetShapeDisabled(Rid area, int shapeIdx, bool disabled)

Parameters

area Rid
shapeIdx int
disabled bool

AreaSetShapeTransform(Rid, int, Transform2D)

Sets the local transform matrix of the area's shape with the given index.

public void AreaSetShapeTransform(Rid area, int shapeIdx, Transform2D transform)

Parameters

area Rid
shapeIdx int
transform Transform2D

AreaSetSpace(Rid, Rid)

Adds the area to the given space, after removing the area from the previously assigned space (if any).

Note: To remove an area from a space without immediately adding it back elsewhere, use PhysicsServer2D.area_set_space(area, RID()).

public void AreaSetSpace(Rid area, Rid space)

Parameters

area Rid
space Rid

AreaSetTransform(Rid, Transform2D)

Sets the transform matrix of the area.

public void AreaSetTransform(Rid area, Transform2D transform)

Parameters

area Rid
transform Transform2D

BodyAddCollisionException(Rid, Rid)

Adds exceptedBody to the body's list of collision exceptions, so that collisions with it are ignored.

public void BodyAddCollisionException(Rid body, Rid exceptedBody)

Parameters

body Rid
exceptedBody Rid

BodyAddConstantCentralForce(Rid, Vector2)

Adds a constant directional force to the body. The force does not affect rotation. The force remains applied over time until cleared with PhysicsServer2D.body_set_constant_force(body, Vector2(0, 0)).

This is equivalent to using BodyAddConstantForce(Rid, Vector2, Vector2?) at the body's center of mass.

public void BodyAddConstantCentralForce(Rid body, Vector2 force)

Parameters

body Rid
force Vector2

BodyAddConstantForce(Rid, Vector2, Vector2?)

Adds a constant positioned force to the body. The force can affect rotation if position is different from the body's center of mass. The force remains applied over time until cleared with PhysicsServer2D.body_set_constant_force(body, Vector2(0, 0)).

position is the offset from the body origin in global coordinates.

public void BodyAddConstantForce(Rid body, Vector2 force, Vector2? position = null)

Parameters

body Rid
force Vector2
position Vector2?

If the parameter is null, then the default value is new Vector2(0, 0).

BodyAddConstantTorque(Rid, float)

Adds a constant rotational force to the body. The force does not affect position. The force remains applied over time until cleared with PhysicsServer2D.body_set_constant_torque(body, 0).

public void BodyAddConstantTorque(Rid body, float torque)

Parameters

body Rid
torque float

BodyAddShape(Rid, Rid, Transform2D?, bool)

Adds a shape to the area, with the given local transform. The shape (together with its transform and disabled properties) is added to an array of shapes, and the shapes of a body are usually referenced by their index in this array.

public void BodyAddShape(Rid body, Rid shape, Transform2D? transform = null, bool disabled = false)

Parameters

body Rid
shape Rid
transform Transform2D?

If the parameter is null, then the default value is Transform2D.Identity.

disabled bool

BodyApplyCentralForce(Rid, Vector2)

Applies a directional force to the body, at the body's center of mass. The force does not affect rotation. A force is time dependent and meant to be applied every physics update.

This is equivalent to using BodyApplyForce(Rid, Vector2, Vector2?) at the body's center of mass.

public void BodyApplyCentralForce(Rid body, Vector2 force)

Parameters

body Rid
force Vector2

BodyApplyCentralImpulse(Rid, Vector2)

Applies a directional impulse to the body, at the body's center of mass. The impulse does not affect rotation.

An impulse is time-independent! Applying an impulse every frame would result in a framerate-dependent force. For this reason, it should only be used when simulating one-time impacts (use the "_force" functions otherwise).

This is equivalent to using BodyApplyImpulse(Rid, Vector2, Vector2?) at the body's center of mass.

public void BodyApplyCentralImpulse(Rid body, Vector2 impulse)

Parameters

body Rid
impulse Vector2

BodyApplyForce(Rid, Vector2, Vector2?)

Applies a positioned force to the body. The force can affect rotation if position is different from the body's center of mass. A force is time dependent and meant to be applied every physics update.

position is the offset from the body origin in global coordinates.

public void BodyApplyForce(Rid body, Vector2 force, Vector2? position = null)

Parameters

body Rid
force Vector2
position Vector2?

If the parameter is null, then the default value is new Vector2(0, 0).

BodyApplyImpulse(Rid, Vector2, Vector2?)

Applies a positioned impulse to the body. The impulse can affect rotation if position is different from the body's center of mass.

An impulse is time-independent! Applying an impulse every frame would result in a framerate-dependent force. For this reason, it should only be used when simulating one-time impacts (use the "_force" functions otherwise).

position is the offset from the body origin in global coordinates.

public void BodyApplyImpulse(Rid body, Vector2 impulse, Vector2? position = null)

Parameters

body Rid
impulse Vector2
position Vector2?

If the parameter is null, then the default value is new Vector2(0, 0).

BodyApplyTorque(Rid, float)

Applies a rotational force to the body. The force does not affect position. A force is time dependent and meant to be applied every physics update.

public void BodyApplyTorque(Rid body, float torque)

Parameters

body Rid
torque float

BodyApplyTorqueImpulse(Rid, float)

Applies a rotational impulse to the body. The impulse does not affect position.

An impulse is time-independent! Applying an impulse every frame would result in a framerate-dependent force. For this reason, it should only be used when simulating one-time impacts (use the "_force" functions otherwise).

public void BodyApplyTorqueImpulse(Rid body, float impulse)

Parameters

body Rid
impulse float

BodyAttachCanvasInstanceId(Rid, ulong)

Attaches the ObjectID of a canvas to the body. Use GetInstanceId() to get the ObjectID of a CanvasLayer.

public void BodyAttachCanvasInstanceId(Rid body, ulong id)

Parameters

body Rid
id ulong

BodyAttachObjectInstanceId(Rid, ulong)

Attaches the ObjectID of an GodotObject to the body. Use GetInstanceId() to get the ObjectID of a CollisionObject2D.

public void BodyAttachObjectInstanceId(Rid body, ulong id)

Parameters

body Rid
id ulong

BodyClearShapes(Rid)

Removes all shapes from the body. This does not delete the shapes themselves, so they can continue to be used elsewhere or added back later.

public void BodyClearShapes(Rid body)

Parameters

body Rid

BodyCreate()

Creates a 2D body object in the physics server, and returns the Rid that identifies it. Use BodyAddShape(Rid, Rid, Transform2D?, bool) to add shapes to it, use BodySetState(Rid, BodyState, Variant) to set its transform, and use BodySetSpace(Rid, Rid) to add the body to a space.

public Rid BodyCreate()

Returns

Rid

BodyGetCanvasInstanceId(Rid)

Returns the ObjectID of the canvas attached to the body. Use @GlobalScope.instance_from_id to retrieve a CanvasLayer from a nonzero ObjectID.

public ulong BodyGetCanvasInstanceId(Rid body)

Parameters

body Rid

Returns

ulong

BodyGetCollisionLayer(Rid)

Returns the physics layer or layers the body belongs to, as a bitmask.

public uint BodyGetCollisionLayer(Rid body)

Parameters

body Rid

Returns

uint

BodyGetCollisionMask(Rid)

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

public uint BodyGetCollisionMask(Rid body)

Parameters

body Rid

Returns

uint

BodyGetCollisionPriority(Rid)

Returns the body's collision priority. This is used in the depenetration phase of BodyTestMotion(Rid, PhysicsTestMotionParameters2D, PhysicsTestMotionResult2D). The higher the priority is, the lower the penetration into the body will be.

public float BodyGetCollisionPriority(Rid body)

Parameters

body Rid

Returns

float

BodyGetConstantForce(Rid)

Returns the body's total constant positional force applied during each physics update.

See BodyAddConstantForce(Rid, Vector2, Vector2?) and BodyAddConstantCentralForce(Rid, Vector2).

public Vector2 BodyGetConstantForce(Rid body)

Parameters

body Rid

Returns

Vector2

BodyGetConstantTorque(Rid)

Returns the body's total constant rotational force applied during each physics update.

See BodyAddConstantTorque(Rid, float).

public float BodyGetConstantTorque(Rid body)

Parameters

body Rid

Returns

float

BodyGetContinuousCollisionDetectionMode(Rid)

Returns the body's continuous collision detection mode (see PhysicsServer2D.CcdMode).

public PhysicsServer2D.CcdMode BodyGetContinuousCollisionDetectionMode(Rid body)

Parameters

body Rid

Returns

PhysicsServer2D.CcdMode

BodyGetDirectState(Rid)

Returns the PhysicsDirectBodyState2D of the body. Returns null if the body is destroyed or not assigned to a space.

public PhysicsDirectBodyState2D BodyGetDirectState(Rid body)

Parameters

body Rid

Returns

PhysicsDirectBodyState2D

BodyGetMaxContactsReported(Rid)

Returns the maximum number of contacts that the body can report. See BodySetMaxContactsReported(Rid, int).

public int BodyGetMaxContactsReported(Rid body)

Parameters

body Rid

Returns

int

BodyGetMode(Rid)

Returns the body's mode (see PhysicsServer2D.BodyMode).

public PhysicsServer2D.BodyMode BodyGetMode(Rid body)

Parameters

body Rid

Returns

PhysicsServer2D.BodyMode

BodyGetObjectInstanceId(Rid)

Returns the ObjectID attached to the body. Use @GlobalScope.instance_from_id to retrieve an GodotObject from a nonzero ObjectID.

public ulong BodyGetObjectInstanceId(Rid body)

Parameters

body Rid

Returns

ulong

BodyGetParam(Rid, BodyParameter)

Returns the value of the given body parameter. See PhysicsServer2D.BodyParameter for the list of available parameters.

public Variant BodyGetParam(Rid body, PhysicsServer2D.BodyParameter param)

Parameters

body Rid
param PhysicsServer2D.BodyParameter

Returns

Variant

BodyGetShape(Rid, int)

Returns the Rid of the shape with the given index in the body's array of shapes.

public Rid BodyGetShape(Rid body, int shapeIdx)

Parameters

body Rid
shapeIdx int

Returns

Rid

BodyGetShapeCount(Rid)

Returns the number of shapes added to the body.

public int BodyGetShapeCount(Rid body)

Parameters

body Rid

Returns

int

BodyGetShapeTransform(Rid, int)

Returns the local transform matrix of the shape with the given index in the area's array of shapes.

public Transform2D BodyGetShapeTransform(Rid body, int shapeIdx)

Parameters

body Rid
shapeIdx int

Returns

Transform2D

BodyGetSpace(Rid)

Returns the Rid of the space assigned to the body. Returns an empty Rid if no space is assigned.

public Rid BodyGetSpace(Rid body)

Parameters

body Rid

Returns

Rid

BodyGetState(Rid, BodyState)

Returns the value of the given state of the body. See PhysicsServer2D.BodyState for the list of available states.

public Variant BodyGetState(Rid body, PhysicsServer2D.BodyState state)

Parameters

body Rid
state PhysicsServer2D.BodyState

Returns

Variant

BodyIsOmittingForceIntegration(Rid)

Returns true if the body uses a callback function to calculate its own physics (see BodySetForceIntegrationCallback(Rid, Callable, Variant)).

public bool BodyIsOmittingForceIntegration(Rid body)

Parameters

body Rid

Returns

bool

BodyRemoveCollisionException(Rid, Rid)

Removes exceptedBody from the body's list of collision exceptions, so that collisions with it are no longer ignored.

public void BodyRemoveCollisionException(Rid body, Rid exceptedBody)

Parameters

body Rid
exceptedBody Rid

BodyRemoveShape(Rid, int)

Removes the shape with the given index from the body's array of shapes. The shape itself is not deleted, so it can continue to be used elsewhere or added back later. As a result of this operation, the body's shapes which used to have indices higher than shapeIdx will have their index decreased by one.

public void BodyRemoveShape(Rid body, int shapeIdx)

Parameters

body Rid
shapeIdx int

BodyResetMassProperties(Rid)

Restores the default inertia and center of mass of the body based on its shapes. This undoes any custom values previously set using BodySetParam(Rid, BodyParameter, Variant).

public void BodyResetMassProperties(Rid body)

Parameters

body Rid

BodySetAxisVelocity(Rid, Vector2)

Modifies the body's linear velocity so that its projection to the axis axis_velocity.normalized() is exactly axis_velocity.length(). This is useful for jumping behavior.

public void BodySetAxisVelocity(Rid body, Vector2 axisVelocity)

Parameters

body Rid
axisVelocity Vector2

BodySetCollisionLayer(Rid, uint)

Sets the physics layer or layers the body belongs to, via a bitmask.

public void BodySetCollisionLayer(Rid body, uint layer)

Parameters

body Rid
layer uint

BodySetCollisionMask(Rid, uint)

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

public void BodySetCollisionMask(Rid body, uint mask)

Parameters

body Rid
mask uint

BodySetCollisionPriority(Rid, float)

Sets the body's collision priority. This is used in the depenetration phase of BodyTestMotion(Rid, PhysicsTestMotionParameters2D, PhysicsTestMotionResult2D). The higher the priority is, the lower the penetration into the body will be.

public void BodySetCollisionPriority(Rid body, float priority)

Parameters

body Rid
priority float

BodySetConstantForce(Rid, Vector2)

Sets the body's total constant positional force applied during each physics update.

See BodyAddConstantForce(Rid, Vector2, Vector2?) and BodyAddConstantCentralForce(Rid, Vector2).

public void BodySetConstantForce(Rid body, Vector2 force)

Parameters

body Rid
force Vector2

BodySetConstantTorque(Rid, float)

Sets the body's total constant rotational force applied during each physics update.

See BodyAddConstantTorque(Rid, float).

public void BodySetConstantTorque(Rid body, float torque)

Parameters

body Rid
torque float

BodySetContinuousCollisionDetectionMode(Rid, CcdMode)

Sets the continuous collision detection mode using one of the PhysicsServer2D.CcdMode constants.

Continuous collision detection tries to predict where a moving body would collide in between physics updates, instead of moving it and correcting its movement if it collided.

public void BodySetContinuousCollisionDetectionMode(Rid body, PhysicsServer2D.CcdMode mode)

Parameters

body Rid
mode PhysicsServer2D.CcdMode

BodySetForceIntegrationCallback(Rid, Callable, Variant)

Sets the function used to calculate physics for the body, if that body allows it (see BodySetOmitForceIntegration(Rid, bool)).

The force integration function takes the following two parameters:

1. a PhysicsDirectBodyState2Dstate: used to retrieve and modify the body's state,

2. a Variantuserdata: optional user data.

Note: This callback is currently not called in Godot Physics.

public void BodySetForceIntegrationCallback(Rid body, Callable callable, Variant userdata = default)

Parameters

body Rid
callable Callable
userdata Variant

BodySetMaxContactsReported(Rid, int)

Sets the maximum number of contacts that the body can report. If amount is greater than zero, then the body will keep track of at most this many contacts with other bodies.

public void BodySetMaxContactsReported(Rid body, int amount)

Parameters

body Rid
amount int

BodySetMode(Rid, BodyMode)

Sets the body's mode. See PhysicsServer2D.BodyMode for the list of available modes.

public void BodySetMode(Rid body, PhysicsServer2D.BodyMode mode)

Parameters

body Rid
mode PhysicsServer2D.BodyMode

BodySetOmitForceIntegration(Rid, bool)

Sets whether the body uses a callback function to calculate its own physics (see BodySetForceIntegrationCallback(Rid, Callable, Variant)).

public void BodySetOmitForceIntegration(Rid body, bool enable)

Parameters

body Rid
enable bool

BodySetParam(Rid, BodyParameter, Variant)

Sets the value of the given body parameter. See PhysicsServer2D.BodyParameter for the list of available parameters.

public void BodySetParam(Rid body, PhysicsServer2D.BodyParameter param, Variant value)

Parameters

body Rid
param PhysicsServer2D.BodyParameter
value Variant

BodySetShape(Rid, int, Rid)

Replaces the body's shape at the given index by another shape, while not affecting the transform, disabled, and one-way collision properties at the same index.

public void BodySetShape(Rid body, int shapeIdx, Rid shape)

Parameters

body Rid
shapeIdx int
shape Rid

BodySetShapeAsOneWayCollision(Rid, int, bool, float)

Sets the one-way collision properties of the body's shape with the given index. If enable is true, the one-way collision direction given by the shape's local upward axis body_get_shape_transform(body, shape_idx).y will be used to ignore collisions with the shape in the opposite direction, and to ensure depenetration of kinematic bodies happens in this direction.

public void BodySetShapeAsOneWayCollision(Rid body, int shapeIdx, bool enable, float margin)

Parameters

body Rid
shapeIdx int
enable bool
margin float

BodySetShapeDisabled(Rid, int, bool)

Sets the disabled property of the body's shape with the given index. If disabled is true, then the shape will be ignored in all collision detection.

public void BodySetShapeDisabled(Rid body, int shapeIdx, bool disabled)

Parameters

body Rid
shapeIdx int
disabled bool

BodySetShapeTransform(Rid, int, Transform2D)

Sets the local transform matrix of the body's shape with the given index.

public void BodySetShapeTransform(Rid body, int shapeIdx, Transform2D transform)

Parameters

body Rid
shapeIdx int
transform Transform2D

BodySetSpace(Rid, Rid)

Adds the body to the given space, after removing the body from the previously assigned space (if any). If the body's mode is set to Rigid, then adding the body to a space will have the following additional effects:

- If the parameter CenterOfMass has never been set explicitly, then the value of that parameter will be recalculated based on the body's shapes.

- If the parameter Inertia is set to a value <= 0.0, then the value of that parameter will be recalculated based on the body's shapes, mass, and center of mass.

Note: To remove a body from a space without immediately adding it back elsewhere, use PhysicsServer2D.body_set_space(body, RID()).

public void BodySetSpace(Rid body, Rid space)

Parameters

body Rid
space Rid

BodySetState(Rid, BodyState, Variant)

Sets the value of a body's state. See PhysicsServer2D.BodyState for the list of available states.

Note: The state change doesn't take effect immediately. The state will change on the next physics frame.

public void BodySetState(Rid body, PhysicsServer2D.BodyState state, Variant value)

Parameters

body Rid
state PhysicsServer2D.BodyState
value Variant

BodyTestMotion(Rid, PhysicsTestMotionParameters2D, PhysicsTestMotionResult2D)

Returns true if a collision would result from moving the body along a motion vector from a given point in space. See PhysicsTestMotionParameters2D for the available motion parameters. Optionally a PhysicsTestMotionResult2D object can be passed, which will be used to store the information about the resulting collision.

public bool BodyTestMotion(Rid body, PhysicsTestMotionParameters2D parameters, PhysicsTestMotionResult2D result = null)

Parameters

body Rid
parameters PhysicsTestMotionParameters2D
result PhysicsTestMotionResult2D

Returns

bool

CapsuleShapeCreate()

Creates a 2D capsule shape in the physics server, and returns the Rid that identifies it. Use ShapeSetData(Rid, Variant) to set the capsule's height and radius.

public Rid CapsuleShapeCreate()

Returns

Rid

CircleShapeCreate()

Creates a 2D circle shape in the physics server, and returns the Rid that identifies it. Use ShapeSetData(Rid, Variant) to set the circle's radius.

public Rid CircleShapeCreate()

Returns

Rid

ConcavePolygonShapeCreate()

Creates a 2D concave polygon shape in the physics server, and returns the Rid that identifies it. Use ShapeSetData(Rid, Variant) to set the concave polygon's segments.

public Rid ConcavePolygonShapeCreate()

Returns

Rid

ConvexPolygonShapeCreate()

Creates a 2D convex polygon shape in the physics server, and returns the Rid that identifies it. Use ShapeSetData(Rid, Variant) to set the convex polygon's points.

public Rid ConvexPolygonShapeCreate()

Returns

Rid

DampedSpringJointGetParam(Rid, DampedSpringParam)

Returns the value of the given damped spring joint parameter. See PhysicsServer2D.DampedSpringParam for the list of available parameters.

public float DampedSpringJointGetParam(Rid joint, PhysicsServer2D.DampedSpringParam param)

Parameters

joint Rid
param PhysicsServer2D.DampedSpringParam

Returns

float

DampedSpringJointSetParam(Rid, DampedSpringParam, float)

Sets the value of the given damped spring joint parameter. See PhysicsServer2D.DampedSpringParam for the list of available parameters.

public void DampedSpringJointSetParam(Rid joint, PhysicsServer2D.DampedSpringParam param, float value)

Parameters

joint Rid
param PhysicsServer2D.DampedSpringParam
value float

FreeRid(Rid)

Destroys any of the objects created by PhysicsServer2D. If the Rid passed is not one of the objects that can be created by PhysicsServer2D, an error will be printed to the console.

public void FreeRid(Rid rid)

Parameters

rid Rid

GetProcessInfo(ProcessInfo)

Returns information about the current state of the 2D physics engine. See PhysicsServer2D.ProcessInfo for the list of available states.

public int GetProcessInfo(PhysicsServer2D.ProcessInfo processInfo)

Parameters

processInfo PhysicsServer2D.ProcessInfo

Returns

int

HasGodotClassMethod(in godot_string_name)

Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.

protected override bool HasGodotClassMethod(in godot_string_name method)

Parameters

method godot_string_name

Name of the method to check for.

Returns

bool

HasGodotClassSignal(in godot_string_name)

Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.

protected override bool HasGodotClassSignal(in godot_string_name signal)

Parameters

signal godot_string_name

Name of the signal to check for.

Returns

bool

InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)

Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.

protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)

Parameters

method godot_string_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool

JointClear(Rid)

Destroys the joint with the given Rid, creates a new uninitialized joint, and makes the Rid refer to this new joint.

public void JointClear(Rid joint)

Parameters

joint Rid

JointCreate()

Creates a 2D joint in the physics server, and returns the Rid that identifies it. To set the joint type, use JointMakeDampedSpring(Rid, Vector2, Vector2, Rid, Rid), JointMakeGroove(Rid, Vector2, Vector2, Vector2, Rid, Rid) or JointMakePin(Rid, Vector2, Rid, Rid). Use JointSetParam(Rid, JointParam, float) to set generic joint parameters.

public Rid JointCreate()

Returns

Rid

JointDisableCollisionsBetweenBodies(Rid, bool)

Sets whether the bodies attached to the Joint2D will collide with each other.

public void JointDisableCollisionsBetweenBodies(Rid joint, bool disable)

Parameters

joint Rid
disable bool

JointGetParam(Rid, JointParam)

Returns the value of the given joint parameter. See PhysicsServer2D.JointParam for the list of available parameters.

public float JointGetParam(Rid joint, PhysicsServer2D.JointParam param)

Parameters

joint Rid
param PhysicsServer2D.JointParam

Returns

float

JointGetType(Rid)

Returns the joint's type (see PhysicsServer2D.JointType).

public PhysicsServer2D.JointType JointGetType(Rid joint)

Parameters

joint Rid

Returns

PhysicsServer2D.JointType

JointIsDisabledCollisionsBetweenBodies(Rid)

Returns whether the bodies attached to the Joint2D will collide with each other.

public bool JointIsDisabledCollisionsBetweenBodies(Rid joint)

Parameters

joint Rid

Returns

bool

JointMakeDampedSpring(Rid, Vector2, Vector2, Rid, Rid)

Makes the joint a damped spring joint, attached at the point anchorA (given in global coordinates) on the body bodyA and at the point anchorB (given in global coordinates) on the body bodyB. To set the parameters which are specific to the damped spring, see DampedSpringJointSetParam(Rid, DampedSpringParam, float).

public void JointMakeDampedSpring(Rid joint, Vector2 anchorA, Vector2 anchorB, Rid bodyA, Rid bodyB = default)

Parameters

joint Rid
anchorA Vector2
anchorB Vector2
bodyA Rid
bodyB Rid

JointMakeGroove(Rid, Vector2, Vector2, Vector2, Rid, Rid)

Makes the joint a groove joint.

public void JointMakeGroove(Rid joint, Vector2 groove1A, Vector2 groove2A, Vector2 anchorB, Rid bodyA = default, Rid bodyB = default)

Parameters

joint Rid
groove1A Vector2
groove2A Vector2
anchorB Vector2
bodyA Rid
bodyB Rid

JointMakePin(Rid, Vector2, Rid, Rid)

Makes the joint a pin joint. If bodyB is an empty Rid, then bodyA is pinned to the point anchor (given in global coordinates); otherwise, bodyA is pinned to bodyB at the point anchor (given in global coordinates). To set the parameters which are specific to the pin joint, see PinJointSetParam(Rid, PinJointParam, float).

public void JointMakePin(Rid joint, Vector2 anchor, Rid bodyA, Rid bodyB = default)

Parameters

joint Rid
anchor Vector2
bodyA Rid
bodyB Rid

JointSetParam(Rid, JointParam, float)

Sets the value of the given joint parameter. See PhysicsServer2D.JointParam for the list of available parameters.

public void JointSetParam(Rid joint, PhysicsServer2D.JointParam param, float value)

Parameters

joint Rid
param PhysicsServer2D.JointParam
value float

PinJointGetFlag(Rid, PinJointFlag)

Gets a pin joint flag (see PhysicsServer2D.PinJointFlag constants).

public bool PinJointGetFlag(Rid joint, PhysicsServer2D.PinJointFlag flag)

Parameters

joint Rid
flag PhysicsServer2D.PinJointFlag

Returns

bool

PinJointGetParam(Rid, PinJointParam)

Returns the value of a pin joint parameter. See PhysicsServer2D.PinJointParam for a list of available parameters.

public float PinJointGetParam(Rid joint, PhysicsServer2D.PinJointParam param)

Parameters

joint Rid
param PhysicsServer2D.PinJointParam

Returns

float

PinJointSetFlag(Rid, PinJointFlag, bool)

Sets a pin joint flag (see PhysicsServer2D.PinJointFlag constants).

public void PinJointSetFlag(Rid joint, PhysicsServer2D.PinJointFlag flag, bool enabled)

Parameters

joint Rid
flag PhysicsServer2D.PinJointFlag
enabled bool

PinJointSetParam(Rid, PinJointParam, float)

Sets a pin joint parameter. See PhysicsServer2D.PinJointParam for a list of available parameters.

public void PinJointSetParam(Rid joint, PhysicsServer2D.PinJointParam param, float value)

Parameters

joint Rid
param PhysicsServer2D.PinJointParam
value float

RectangleShapeCreate()

Creates a 2D rectangle shape in the physics server, and returns the Rid that identifies it. Use ShapeSetData(Rid, Variant) to set the rectangle's half-extents.

public Rid RectangleShapeCreate()

Returns

Rid

SegmentShapeCreate()

Creates a 2D segment shape in the physics server, and returns the Rid that identifies it. Use ShapeSetData(Rid, Variant) to set the segment's start and end points.

public Rid SegmentShapeCreate()

Returns

Rid

SeparationRayShapeCreate()

Creates a 2D separation ray shape in the physics server, and returns the Rid that identifies it. Use ShapeSetData(Rid, Variant) to set the shape's length and slide_on_slope properties.

public Rid SeparationRayShapeCreate()

Returns

Rid

SetActive(bool)

Activates or deactivates the 2D physics server. If active is false, then the physics server will not do anything in its physics step.

public void SetActive(bool active)

Parameters

active bool

ShapeGetData(Rid)

Returns the shape data that defines the configuration of the shape, such as the half-extents of a rectangle or the segments of a concave shape. See ShapeSetData(Rid, Variant) for the precise format of this data in each case.

public Variant ShapeGetData(Rid shape)

Parameters

shape Rid

Returns

Variant

ShapeGetType(Rid)

Returns the shape's type (see PhysicsServer2D.ShapeType).

public PhysicsServer2D.ShapeType ShapeGetType(Rid shape)

Parameters

shape Rid

Returns

PhysicsServer2D.ShapeType

ShapeSetData(Rid, Variant)

Sets the shape data that defines the configuration of the shape. The data to be passed depends on the shape's type (see ShapeGetType(Rid)):

- WorldBoundary: an array of length two containing a Vector2normal direction and a float distance d,

- SeparationRay: a dictionary containing the key length with a float value and the key slide_on_slope with a bool value,

- Segment: a Rect2rect containing the first point of the segment in rect.position and the second point of the segment in rect.size,

- Circle: a floatradius,

- Rectangle: a Vector2half_extents,

- Capsule: an array of length two (or a Vector2) containing a floatheight and a floatradius,

- ConvexPolygon: either a Vector2[] of points defining a convex polygon in counterclockwise order (the clockwise outward normal of each segment formed by consecutive points is calculated internally), or a float[] of length divisible by four so that every 4-tuple of floats contains the coordinates of a point followed by the coordinates of the clockwise outward normal vector to the segment between the current point and the next point,

- ConcavePolygon: a Vector2[] of length divisible by two (each pair of points forms one segment).

Warning: In the case of ConvexPolygon, this method does not check if the points supplied actually form a convex polygon (unlike the Polygon property).

public void ShapeSetData(Rid shape, Variant data)

Parameters

shape Rid
data Variant

SpaceCreate()

Creates a 2D space in the physics server, and returns the Rid that identifies it. A space contains bodies and areas, and controls the stepping of the physics simulation of the objects in it.

public Rid SpaceCreate()

Returns

Rid

SpaceGetDirectState(Rid)

Returns the state of a space, a PhysicsDirectSpaceState2D. This object can be used for collision/intersection queries.

public PhysicsDirectSpaceState2D SpaceGetDirectState(Rid space)

Parameters

space Rid

Returns

PhysicsDirectSpaceState2D

SpaceGetParam(Rid, SpaceParameter)

Returns the value of the given space parameter. See PhysicsServer2D.SpaceParameter for the list of available parameters.

public float SpaceGetParam(Rid space, PhysicsServer2D.SpaceParameter param)

Parameters

space Rid
param PhysicsServer2D.SpaceParameter

Returns

float

SpaceIsActive(Rid)

Returns true if the space is active.

public bool SpaceIsActive(Rid space)

Parameters

space Rid

Returns

bool

SpaceSetActive(Rid, bool)

Activates or deactivates the space. If active is false, then the physics server will not do anything with this space in its physics step.

public void SpaceSetActive(Rid space, bool active)

Parameters

space Rid
active bool

SpaceSetParam(Rid, SpaceParameter, float)

Sets the value of the given space parameter. See PhysicsServer2D.SpaceParameter for the list of available parameters.

public void SpaceSetParam(Rid space, PhysicsServer2D.SpaceParameter param, float value)

Parameters

space Rid
param PhysicsServer2D.SpaceParameter
value float

WorldBoundaryShapeCreate()

Creates a 2D world boundary shape in the physics server, and returns the Rid that identifies it. Use ShapeSetData(Rid, Variant) to set the shape's normal direction and distance properties.

public Rid WorldBoundaryShapeCreate()

Returns

Rid