PhysicsDirectBodyState2D
Provides direct access to a physics body in the PhysicsServer2D.
Provides direct access to a physics body in the PhysicsServer2D.
Provides direct access to a physics body in the PhysicsServer2D, allowing safe changes to physics properties. This object is passed via the direct state callback of RigidBody2D, and is intended for changing the direct state of that body. See RigidBody2D._IntegrateForces.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Properties14
AngularVelocityProperty
public float AngularVelocity { get; set; }The body's rotational velocity in radians per second.
CenterOfMassProperty
public Vector2 CenterOfMass { get; }The body's center of mass position relative to the body's center in the global coordinate system.
CenterOfMassLocalProperty
public Vector2 CenterOfMassLocal { get; }The body's center of mass position in the body's local coordinate system.
CollisionLayerProperty
public uint CollisionLayer { get; set; }The body's collision layer.
CollisionMaskProperty
public uint CollisionMask { get; set; }The body's collision mask.
InverseInertiaProperty
public float InverseInertia { get; }The inverse of the inertia of the body.
InverseMassProperty
public float InverseMass { get; }The inverse of the mass of the body.
LinearVelocityProperty
public Vector2 LinearVelocity { get; set; }The body's linear velocity in pixels per second.
SleepingProperty
public bool Sleeping { get; set; }If true, this body is currently sleeping (not active).
StepProperty
public float Step { get; }The timestep (delta) used for the simulation.
TotalAngularDampProperty
public float TotalAngularDamp { get; }The rate at which the body stops rotating, if there are not any other forces moving it.
TotalGravityProperty
public Vector2 TotalGravity { get; }The total gravity vector being currently applied to this body.
TotalLinearDampProperty
public float TotalLinearDamp { get; }The rate at which the body stops moving, if there are not any other forces moving it.
TransformProperty
public Transform2D Transform { get; set; }The body's transformation matrix.
Methods48
AddConstantCentralForcevoid
public void AddConstantCentralForce(Vector2? force = default);Adds a constant directional force without affecting rotation that keeps being applied over time until cleared with constant_force = Vector2(0, 0).
This is equivalent to using PhysicsDirectBodyState2D.AddConstantForce at the body's center of mass.
| Name | Type | Default |
|---|---|---|
force | Vector2? | default |
forceIf the parameter is null, then the default value is new Vector2(0.0f, 0.0f).
AddConstantForcevoid
public void AddConstantForce(Vector2 force, Vector2? position = default);Adds a constant positioned force to the body that keeps being applied over time until cleared with constant_force = Vector2(0, 0).
position is the offset from the body origin in global coordinates.
| Name | Type | Default |
|---|---|---|
force | Vector2 | — |
position | Vector2? | default |
positionIf the parameter is null, then the default value is new Vector2(0.0f, 0.0f).
AddConstantTorquevoid
public void AddConstantTorque(float torque);Adds a constant rotational force without affecting position that keeps being applied over time until cleared with constant_torque = 0.
| Name | Type | Default |
|---|---|---|
torque | float | — |
ApplyCentralForcevoid
public void ApplyCentralForce(Vector2? force = default);Applies a directional force without affecting rotation. A force is time dependent and meant to be applied every physics update.
This is equivalent to using PhysicsDirectBodyState2D.ApplyForce at the body's center of mass.
| Name | Type | Default |
|---|---|---|
force | Vector2? | default |
forceIf the parameter is null, then the default value is new Vector2(0.0f, 0.0f).
ApplyCentralImpulsevoid
public void ApplyCentralImpulse(Vector2 impulse);Applies a directional impulse without affecting 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 PhysicsDirectBodyState2D.ApplyImpulse at the body's center of mass.
| Name | Type | Default |
|---|---|---|
impulse | Vector2 | — |
ApplyForcevoid
public void ApplyForce(Vector2 force, Vector2? position = default);Applies a positioned force to the body. A force is time dependent and meant to be applied every physics update.
position is the offset from the body origin in global coordinates.
| Name | Type | Default |
|---|---|---|
force | Vector2 | — |
position | Vector2? | default |
positionIf the parameter is null, then the default value is new Vector2(0.0f, 0.0f).
ApplyImpulsevoid
public void ApplyImpulse(Vector2 impulse, Vector2? position = default);Applies a positioned impulse to the body.
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.
| Name | Type | Default |
|---|---|---|
impulse | Vector2 | — |
position | Vector2? | default |
positionIf the parameter is null, then the default value is new Vector2(0.0f, 0.0f).
ApplyTorquevoid
public void ApplyTorque(float torque);Applies a rotational force without affecting position. A force is time dependent and meant to be applied every physics update.
Note: PhysicsDirectBodyState2D.InverseInertia is required for this to work. To have PhysicsDirectBodyState2D.InverseInertia, an active CollisionShape2D must be a child of the node, or you can manually set PhysicsDirectBodyState2D.InverseInertia.
| Name | Type | Default |
|---|---|---|
torque | float | — |
ApplyTorqueImpulsevoid
public void ApplyTorqueImpulse(float impulse);Applies a rotational impulse to the body without affecting the 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).
Note: PhysicsDirectBodyState2D.InverseInertia is required for this to work. To have PhysicsDirectBodyState2D.InverseInertia, an active CollisionShape2D must be a child of the node, or you can manually set PhysicsDirectBodyState2D.InverseInertia.
| Name | Type | Default |
|---|---|---|
impulse | float | — |
GetAngularVelocityfloat
public float GetAngularVelocity();floatGetCenterOfMassVector2
public Vector2 GetCenterOfMass();Vector2GetCenterOfMassLocalVector2
public Vector2 GetCenterOfMassLocal();Vector2GetCollisionLayeruint
public uint GetCollisionLayer();uintGetCollisionMaskuint
public uint GetCollisionMask();uintGetConstantForceVector2
public Vector2 GetConstantForce();Returns the body's total constant positional forces applied during each physics update.
See PhysicsDirectBodyState2D.AddConstantForce and PhysicsDirectBodyState2D.AddConstantCentralForce.
Vector2GetConstantTorquefloat
public float GetConstantTorque();Returns the body's total constant rotational forces applied during each physics update.
See PhysicsDirectBodyState2D.AddConstantTorque.
floatGetContactColliderRid
public Rid GetContactCollider(int contactIdx);Returns the collider's Rid.
| Name | Type | Default |
|---|---|---|
contactIdx | int | — |
RidGetContactColliderIdulong
public ulong GetContactColliderId(int contactIdx);Returns the collider's object id.
| Name | Type | Default |
|---|---|---|
contactIdx | int | — |
ulongGetContactColliderObjectReckfellObject
public ReckfellObject GetContactColliderObject(int contactIdx);Returns the collider object. This depends on how it was created (will return a scene node if such was used to create it).
| Name | Type | Default |
|---|---|---|
contactIdx | int | — |
ReckfellObjectGetContactColliderPositionVector2
public Vector2 GetContactColliderPosition(int contactIdx);Returns the position of the contact point on the collider in the global coordinate system.
| Name | Type | Default |
|---|---|---|
contactIdx | int | — |
Vector2GetContactColliderShapeint
public int GetContactColliderShape(int contactIdx);Returns the collider's shape index.
| Name | Type | Default |
|---|---|---|
contactIdx | int | — |
intGetContactColliderVelocityAtPositionVector2
public Vector2 GetContactColliderVelocityAtPosition(int contactIdx);Returns the velocity vector at the collider's contact point.
| Name | Type | Default |
|---|---|---|
contactIdx | int | — |
Vector2GetContactCountint
public int GetContactCount();Returns the number of contacts this body has with other bodies.
Note: By default, this returns 0 unless bodies are configured to monitor contacts. See RigidBody2D.ContactMonitor.
intGetContactImpulseVector2
public Vector2 GetContactImpulse(int contactIdx);Returns the impulse created by the contact.
| Name | Type | Default |
|---|---|---|
contactIdx | int | — |
Vector2GetContactLocalNormalVector2
public Vector2 GetContactLocalNormal(int contactIdx);Returns the local normal at the contact point.
| Name | Type | Default |
|---|---|---|
contactIdx | int | — |
Vector2GetContactLocalPositionVector2
public Vector2 GetContactLocalPosition(int contactIdx);Returns the position of the contact point on the body in the global coordinate system.
| Name | Type | Default |
|---|---|---|
contactIdx | int | — |
Vector2GetContactLocalShapeint
public int GetContactLocalShape(int contactIdx);Returns the local shape index of the collision.
| Name | Type | Default |
|---|---|---|
contactIdx | int | — |
intGetContactLocalVelocityAtPositionVector2
public Vector2 GetContactLocalVelocityAtPosition(int contactIdx);Returns the velocity vector at the body's contact point.
| Name | Type | Default |
|---|---|---|
contactIdx | int | — |
Vector2GetInverseInertiafloat
public float GetInverseInertia();floatGetInverseMassfloat
public float GetInverseMass();floatGetLinearVelocityVector2
public Vector2 GetLinearVelocity();Vector2GetSpaceStatePhysicsDirectSpaceState2D
public PhysicsDirectSpaceState2D GetSpaceState();Returns the current state of the space, useful for queries.
PhysicsDirectSpaceState2DGetStepfloat
public float GetStep();floatGetTotalAngularDampfloat
public float GetTotalAngularDamp();floatGetTotalGravityVector2
public Vector2 GetTotalGravity();Vector2GetTotalLinearDampfloat
public float GetTotalLinearDamp();floatGetTransformTransform2D
public Transform2D GetTransform();Transform2DGetVelocityAtLocalPositionVector2
public Vector2 GetVelocityAtLocalPosition(Vector2 localPosition);Returns the body's velocity at the given relative position.
local_position is the offset from the body origin in global coordinates.
| Name | Type | Default |
|---|---|---|
localPosition | Vector2 | — |
Vector2IntegrateForcesvoid
public void IntegrateForces();Updates the body's linear and angular velocity by applying gravity and damping for the equivalent of one physics tick.
IsSleepingbool
public bool IsSleeping();boolSetAngularVelocityvoid
public void SetAngularVelocity(float velocity);| Name | Type | Default |
|---|---|---|
velocity | float | — |
SetCollisionLayervoid
public void SetCollisionLayer(uint layer);| Name | Type | Default |
|---|---|---|
layer | uint | — |
SetCollisionMaskvoid
public void SetCollisionMask(uint mask);| Name | Type | Default |
|---|---|---|
mask | uint | — |
SetConstantForcevoid
public void SetConstantForce(Vector2 force);Sets the body's total constant positional forces applied during each physics update.
See PhysicsDirectBodyState2D.AddConstantForce and PhysicsDirectBodyState2D.AddConstantCentralForce.
| Name | Type | Default |
|---|---|---|
force | Vector2 | — |
SetConstantTorquevoid
public void SetConstantTorque(float torque);Sets the body's total constant rotational forces applied during each physics update.
See PhysicsDirectBodyState2D.AddConstantTorque.
| Name | Type | Default |
|---|---|---|
torque | float | — |
SetLinearVelocityvoid
public void SetLinearVelocity(Vector2 velocity);| Name | Type | Default |
|---|---|---|
velocity | Vector2 | — |
SetSleepStatevoid
public void SetSleepState(bool enabled);| Name | Type | Default |
|---|---|---|
enabled | bool | — |
SetTransformvoid
public void SetTransform(Transform2D transform);| Name | Type | Default |
|---|---|---|
transform | Transform2D | — |