reckfellENGINE

PhysicsDirectBodyState2D

Provides direct access to a physics body in the PhysicsServer2D.

On this page
class PhysicsDirectBodyState2DReckfellSharpInherits ReckfellObject

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
# AngularVelocity
C#
public float AngularVelocity { get; set; }

The body's rotational velocity in radians per second.

CenterOfMassProperty
# CenterOfMass
C#
public Vector2 CenterOfMass { get; }

The body's center of mass position relative to the body's center in the global coordinate system.

CenterOfMassLocalProperty
# CenterOfMassLocal
C#
public Vector2 CenterOfMassLocal { get; }

The body's center of mass position in the body's local coordinate system.

CollisionLayerProperty
# CollisionLayer
C#
public uint CollisionLayer { get; set; }

The body's collision layer.

CollisionMaskProperty
# CollisionMask
C#
public uint CollisionMask { get; set; }

The body's collision mask.

InverseInertiaProperty
# InverseInertia
C#
public float InverseInertia { get; }

The inverse of the inertia of the body.

InverseMassProperty
# InverseMass
C#
public float InverseMass { get; }

The inverse of the mass of the body.

LinearVelocityProperty
# LinearVelocity
C#
public Vector2 LinearVelocity { get; set; }

The body's linear velocity in pixels per second.

SleepingProperty
# Sleeping
C#
public bool Sleeping { get; set; }

If true, this body is currently sleeping (not active).

StepProperty
# Step
C#
public float Step { get; }

The timestep (delta) used for the simulation.

TotalAngularDampProperty
# TotalAngularDamp
C#
public float TotalAngularDamp { get; }

The rate at which the body stops rotating, if there are not any other forces moving it.

TotalGravityProperty
# TotalGravity
C#
public Vector2 TotalGravity { get; }

The total gravity vector being currently applied to this body.

TotalLinearDampProperty
# TotalLinearDamp
C#
public float TotalLinearDamp { get; }

The rate at which the body stops moving, if there are not any other forces moving it.

TransformProperty
# Transform
C#
public Transform2D Transform { get; set; }

The body's transformation matrix.

Methods48

AddConstantCentralForcevoid
# AddConstantCentralForce
C#
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.

Parameters
NameTypeDefault
forceVector2?default
force

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

AddConstantForcevoid
# AddConstantForce
C#
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.

Parameters
NameTypeDefault
forceVector2—
positionVector2?default
position

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

AddConstantTorquevoid
# AddConstantTorque
C#
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.

Parameters
NameTypeDefault
torquefloat—
ApplyCentralForcevoid
# ApplyCentralForce
C#
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.

Parameters
NameTypeDefault
forceVector2?default
force

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

ApplyCentralImpulsevoid
# ApplyCentralImpulse
C#
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.

Parameters
NameTypeDefault
impulseVector2—
ApplyForcevoid
# ApplyForce
C#
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.

Parameters
NameTypeDefault
forceVector2—
positionVector2?default
position

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

ApplyImpulsevoid
# ApplyImpulse
C#
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.

Parameters
NameTypeDefault
impulseVector2—
positionVector2?default
position

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

ApplyTorquevoid
# ApplyTorque
C#
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.

Parameters
NameTypeDefault
torquefloat—
ApplyTorqueImpulsevoid
# ApplyTorqueImpulse
C#
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.

Parameters
NameTypeDefault
impulsefloat—
GetAngularVelocityfloat
# GetAngularVelocity
C#
public float GetAngularVelocity();
Returns float
GetCenterOfMassVector2
# GetCenterOfMass
C#
public Vector2 GetCenterOfMass();
Returns Vector2
GetCenterOfMassLocalVector2
# GetCenterOfMassLocal
C#
public Vector2 GetCenterOfMassLocal();
Returns Vector2
GetCollisionLayeruint
# GetCollisionLayer
C#
public uint GetCollisionLayer();
Returns uint
GetCollisionMaskuint
# GetCollisionMask
C#
public uint GetCollisionMask();
Returns uint
GetConstantForceVector2
# GetConstantForce
C#
public Vector2 GetConstantForce();

Returns the body's total constant positional forces applied during each physics update. See PhysicsDirectBodyState2D.AddConstantForce and PhysicsDirectBodyState2D.AddConstantCentralForce.

Returns Vector2
GetConstantTorquefloat
# GetConstantTorque
C#
public float GetConstantTorque();

Returns the body's total constant rotational forces applied during each physics update. See PhysicsDirectBodyState2D.AddConstantTorque.

Returns float
GetContactColliderRid
# GetContactCollider
C#
public Rid GetContactCollider(int contactIdx);

Returns the collider's Rid.

Parameters
NameTypeDefault
contactIdxint—
Returns Rid
GetContactColliderIdulong
# GetContactColliderId
C#
public ulong GetContactColliderId(int contactIdx);

Returns the collider's object id.

Parameters
NameTypeDefault
contactIdxint—
Returns ulong
GetContactColliderObjectReckfellObject
# GetContactColliderObject
C#
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).

Parameters
NameTypeDefault
contactIdxint—
Returns ReckfellObject
GetContactColliderPositionVector2
# GetContactColliderPosition
C#
public Vector2 GetContactColliderPosition(int contactIdx);

Returns the position of the contact point on the collider in the global coordinate system.

Parameters
NameTypeDefault
contactIdxint—
Returns Vector2
GetContactColliderShapeint
# GetContactColliderShape
C#
public int GetContactColliderShape(int contactIdx);

Returns the collider's shape index.

Parameters
NameTypeDefault
contactIdxint—
Returns int
GetContactColliderVelocityAtPositionVector2
# GetContactColliderVelocityAtPosition
C#
public Vector2 GetContactColliderVelocityAtPosition(int contactIdx);

Returns the velocity vector at the collider's contact point.

Parameters
NameTypeDefault
contactIdxint—
Returns Vector2
GetContactCountint
# GetContactCount
C#
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.

Returns int
GetContactImpulseVector2
# GetContactImpulse
C#
public Vector2 GetContactImpulse(int contactIdx);

Returns the impulse created by the contact.

Parameters
NameTypeDefault
contactIdxint—
Returns Vector2
GetContactLocalNormalVector2
# GetContactLocalNormal
C#
public Vector2 GetContactLocalNormal(int contactIdx);

Returns the local normal at the contact point.

Parameters
NameTypeDefault
contactIdxint—
Returns Vector2
GetContactLocalPositionVector2
# GetContactLocalPosition
C#
public Vector2 GetContactLocalPosition(int contactIdx);

Returns the position of the contact point on the body in the global coordinate system.

Parameters
NameTypeDefault
contactIdxint—
Returns Vector2
GetContactLocalShapeint
# GetContactLocalShape
C#
public int GetContactLocalShape(int contactIdx);

Returns the local shape index of the collision.

Parameters
NameTypeDefault
contactIdxint—
Returns int
GetContactLocalVelocityAtPositionVector2
# GetContactLocalVelocityAtPosition
C#
public Vector2 GetContactLocalVelocityAtPosition(int contactIdx);

Returns the velocity vector at the body's contact point.

Parameters
NameTypeDefault
contactIdxint—
Returns Vector2
GetInverseInertiafloat
# GetInverseInertia
C#
public float GetInverseInertia();
Returns float
GetInverseMassfloat
# GetInverseMass
C#
public float GetInverseMass();
Returns float
GetLinearVelocityVector2
# GetLinearVelocity
C#
public Vector2 GetLinearVelocity();
Returns Vector2
GetSpaceStatePhysicsDirectSpaceState2D
# GetSpaceState
C#
public PhysicsDirectSpaceState2D GetSpaceState();

Returns the current state of the space, useful for queries.

Returns PhysicsDirectSpaceState2D
GetStepfloat
# GetStep
C#
public float GetStep();
Returns float
GetTotalAngularDampfloat
# GetTotalAngularDamp
C#
public float GetTotalAngularDamp();
Returns float
GetTotalGravityVector2
# GetTotalGravity
C#
public Vector2 GetTotalGravity();
Returns Vector2
GetTotalLinearDampfloat
# GetTotalLinearDamp
C#
public float GetTotalLinearDamp();
Returns float
GetTransformTransform2D
# GetTransform
C#
public Transform2D GetTransform();
Returns Transform2D
GetVelocityAtLocalPositionVector2
# GetVelocityAtLocalPosition
C#
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.

Parameters
NameTypeDefault
localPositionVector2—
Returns Vector2
IntegrateForcesvoid
# IntegrateForces
C#
public void IntegrateForces();

Updates the body's linear and angular velocity by applying gravity and damping for the equivalent of one physics tick.

IsSleepingbool
# IsSleeping
C#
public bool IsSleeping();
Returns bool
SetAngularVelocityvoid
# SetAngularVelocity
C#
public void SetAngularVelocity(float velocity);
Parameters
NameTypeDefault
velocityfloat—
SetCollisionLayervoid
# SetCollisionLayer
C#
public void SetCollisionLayer(uint layer);
Parameters
NameTypeDefault
layeruint—
SetCollisionMaskvoid
# SetCollisionMask
C#
public void SetCollisionMask(uint mask);
Parameters
NameTypeDefault
maskuint—
SetConstantForcevoid
# SetConstantForce
C#
public void SetConstantForce(Vector2 force);

Sets the body's total constant positional forces applied during each physics update. See PhysicsDirectBodyState2D.AddConstantForce and PhysicsDirectBodyState2D.AddConstantCentralForce.

Parameters
NameTypeDefault
forceVector2—
SetConstantTorquevoid
# SetConstantTorque
C#
public void SetConstantTorque(float torque);

Sets the body's total constant rotational forces applied during each physics update. See PhysicsDirectBodyState2D.AddConstantTorque.

Parameters
NameTypeDefault
torquefloat—
SetLinearVelocityvoid
# SetLinearVelocity
C#
public void SetLinearVelocity(Vector2 velocity);
Parameters
NameTypeDefault
velocityVector2—
SetSleepStatevoid
# SetSleepState
C#
public void SetSleepState(bool enabled);
Parameters
NameTypeDefault
enabledbool—
SetTransformvoid
# SetTransform
C#
public void SetTransform(Transform2D transform);
Parameters
NameTypeDefault
transformTransform2D—
Reckfell Engine documentationBack to top ↑
QUICK LINKSGetting startedEntity hierarchyC# & .NET 10Scenes and prefabs
Reckfell guides and full API K
reckfellENGINE
RECKFELL ACCOUNT

Sign in

Sign in to your Reckfell account.

One account for the entire Reckfell platform.