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
Ridshape
Ridtransform
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
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
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
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
AreaGetCollisionLayer(Rid)
Returns the physics layer or layers the area belongs to, as a bitmask.
public uint AreaGetCollisionLayer(Rid area)
Parameters
area
Rid
Returns
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
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
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
Ridparam
PhysicsServer2D.AreaParameter
Returns
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
Returns
AreaGetShapeCount(Rid)
Returns the number of shapes added to the area.
public int AreaGetShapeCount(Rid area)
Parameters
area
Rid
Returns
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
Returns
AreaGetSpace(Rid)
public Rid AreaGetSpace(Rid area)
Parameters
area
Rid
Returns
AreaGetTransform(Rid)
Returns the transform matrix of the area.
public Transform2D AreaGetTransform(Rid area)
Parameters
area
Rid
Returns
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
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
AreaSetCollisionLayer(Rid, uint)
Assigns the area to one or many physics layers, via a bitmask.
public void AreaSetCollisionLayer(Rid area, uint layer)
Parameters
AreaSetCollisionMask(Rid, uint)
Sets which physics layers the area will monitor, via a bitmask.
public void AreaSetCollisionMask(Rid area, uint mask)
Parameters
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
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
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
Ridparam
PhysicsServer2D.AreaParametervalue
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
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
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
RidshapeIdx
inttransform
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
AreaSetTransform(Rid, Transform2D)
Sets the transform matrix of the area.
public void AreaSetTransform(Rid area, Transform2D transform)
Parameters
area
Ridtransform
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
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
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
Ridforce
Vector2position
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
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
Ridshape
Ridtransform
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
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
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
Ridforce
Vector2position
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
Ridimpulse
Vector2position
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
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
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
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
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
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
BodyGetCollisionLayer(Rid)
Returns the physics layer or layers the body belongs to, as a bitmask.
public uint BodyGetCollisionLayer(Rid body)
Parameters
body
Rid
Returns
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
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
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
BodyGetConstantTorque(Rid)
Returns the body's total constant rotational force applied during each physics update.
public float BodyGetConstantTorque(Rid body)
Parameters
body
Rid
Returns
BodyGetContinuousCollisionDetectionMode(Rid)
Returns the body's continuous collision detection mode (see PhysicsServer2D.CcdMode).
public PhysicsServer2D.CcdMode BodyGetContinuousCollisionDetectionMode(Rid body)
Parameters
body
Rid
Returns
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
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
BodyGetMode(Rid)
Returns the body's mode (see PhysicsServer2D.BodyMode).
public PhysicsServer2D.BodyMode BodyGetMode(Rid body)
Parameters
body
Rid
Returns
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
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
Ridparam
PhysicsServer2D.BodyParameter
Returns
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
Returns
BodyGetShapeCount(Rid)
Returns the number of shapes added to the body.
public int BodyGetShapeCount(Rid body)
Parameters
body
Rid
Returns
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
Returns
BodyGetSpace(Rid)
public Rid BodyGetSpace(Rid body)
Parameters
body
Rid
Returns
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
Ridstate
PhysicsServer2D.BodyState
Returns
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
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
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
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
BodySetCollisionLayer(Rid, uint)
Sets the physics layer or layers the body belongs to, via a bitmask.
public void BodySetCollisionLayer(Rid body, uint layer)
Parameters
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
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
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
BodySetConstantTorque(Rid, float)
Sets the body's total constant rotational force applied during each physics update.
public void BodySetConstantTorque(Rid body, float torque)
Parameters
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
Ridmode
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
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
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
Ridmode
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
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
Ridparam
PhysicsServer2D.BodyParametervalue
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
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
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
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
RidshapeIdx
inttransform
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
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
Ridstate
PhysicsServer2D.BodyStatevalue
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
Ridparameters
PhysicsTestMotionParameters2Dresult
PhysicsTestMotionResult2D
Returns
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
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
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
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
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
Ridparam
PhysicsServer2D.DampedSpringParam
Returns
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
Ridparam
PhysicsServer2D.DampedSpringParamvalue
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
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_nameName of the method to check for.
Returns
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_nameName of the signal to check for.
Returns
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_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
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
JointDisableCollisionsBetweenBodies(Rid, bool)
Sets whether the bodies attached to the Joint2D will collide with each other.
public void JointDisableCollisionsBetweenBodies(Rid joint, bool disable)
Parameters
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
Ridparam
PhysicsServer2D.JointParam
Returns
JointGetType(Rid)
Returns the joint's type (see PhysicsServer2D.JointType).
public PhysicsServer2D.JointType JointGetType(Rid joint)
Parameters
joint
Rid
Returns
JointIsDisabledCollisionsBetweenBodies(Rid)
Returns whether the bodies attached to the Joint2D will collide with each other.
public bool JointIsDisabledCollisionsBetweenBodies(Rid joint)
Parameters
joint
Rid
Returns
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
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
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
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
Ridparam
PhysicsServer2D.JointParamvalue
float
PinJointGetFlag(Rid, PinJointFlag)
Gets a pin joint flag (see PhysicsServer2D.PinJointFlag constants).
public bool PinJointGetFlag(Rid joint, PhysicsServer2D.PinJointFlag flag)
Parameters
joint
Ridflag
PhysicsServer2D.PinJointFlag
Returns
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
Ridparam
PhysicsServer2D.PinJointParam
Returns
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
Ridflag
PhysicsServer2D.PinJointFlagenabled
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
Ridparam
PhysicsServer2D.PinJointParamvalue
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
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
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
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
ShapeGetType(Rid)
Returns the shape's type (see PhysicsServer2D.ShapeType).
public PhysicsServer2D.ShapeType ShapeGetType(Rid shape)
Parameters
shape
Rid
Returns
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
,
- 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
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
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
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
Ridparam
PhysicsServer2D.SpaceParameter
Returns
SpaceIsActive(Rid)
Returns true
if the space is active.
public bool SpaceIsActive(Rid space)
Parameters
space
Rid
Returns
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
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
Ridparam
PhysicsServer2D.SpaceParametervalue
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()