Table of Contents

Class PhysicsDirectBodyState2D

Namespace
Godot
Assembly
GodotSharp.dll

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 _IntegrateForces(PhysicsDirectBodyState2D).

public class PhysicsDirectBodyState2D : GodotObject, IDisposable
Inheritance
PhysicsDirectBodyState2D
Implements
Derived
Inherited Members

Properties

AngularVelocity

The body's rotational velocity in radians per second.

public float AngularVelocity { get; set; }

Property Value

float

CenterOfMass

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

public Vector2 CenterOfMass { get; }

Property Value

Vector2

CenterOfMassLocal

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

public Vector2 CenterOfMassLocal { get; }

Property Value

Vector2

InverseInertia

The inverse of the inertia of the body.

public float InverseInertia { get; }

Property Value

float

InverseMass

The inverse of the mass of the body.

public float InverseMass { get; }

Property Value

float

LinearVelocity

The body's linear velocity in pixels per second.

public Vector2 LinearVelocity { get; set; }

Property Value

Vector2

Sleeping

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

public bool Sleeping { get; set; }

Property Value

bool

Step

The timestep (delta) used for the simulation.

public float Step { get; }

Property Value

float

TotalAngularDamp

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

public float TotalAngularDamp { get; }

Property Value

float

TotalGravity

The total gravity vector being currently applied to this body.

public Vector2 TotalGravity { get; }

Property Value

Vector2

TotalLinearDamp

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

public float TotalLinearDamp { get; }

Property Value

float

Transform

The body's transformation matrix.

public Transform2D Transform { get; set; }

Property Value

Transform2D

Methods

AddConstantCentralForce(Vector2?)

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 AddConstantForce(Vector2, Vector2?) at the body's center of mass.

public void AddConstantCentralForce(Vector2? force = null)

Parameters

force Vector2?

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

AddConstantForce(Vector2, Vector2?)

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.

public void AddConstantForce(Vector2 force, Vector2? position = null)

Parameters

force Vector2
position Vector2?

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

AddConstantTorque(float)

Adds a constant rotational force without affecting position that keeps being applied over time until cleared with constant_torque = 0.

public void AddConstantTorque(float torque)

Parameters

torque float

ApplyCentralForce(Vector2?)

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 ApplyForce(Vector2, Vector2?) at the body's center of mass.

public void ApplyCentralForce(Vector2? force = null)

Parameters

force Vector2?

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

ApplyCentralImpulse(Vector2)

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 ApplyImpulse(Vector2, Vector2?) at the body's center of mass.

public void ApplyCentralImpulse(Vector2 impulse)

Parameters

impulse Vector2

ApplyForce(Vector2, Vector2?)

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.

public void ApplyForce(Vector2 force, Vector2? position = null)

Parameters

force Vector2
position Vector2?

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

ApplyImpulse(Vector2, Vector2?)

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.

public void ApplyImpulse(Vector2 impulse, Vector2? position = null)

Parameters

impulse Vector2
position Vector2?

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

ApplyTorque(float)

Applies a rotational force without affecting position. A force is time dependent and meant to be applied every physics update.

Note: InverseInertia is required for this to work. To have InverseInertia, an active CollisionShape2D must be a child of the node, or you can manually set InverseInertia.

public void ApplyTorque(float torque)

Parameters

torque float

ApplyTorqueImpulse(float)

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: InverseInertia is required for this to work. To have InverseInertia, an active CollisionShape2D must be a child of the node, or you can manually set InverseInertia.

public void ApplyTorqueImpulse(float impulse)

Parameters

impulse float

GetConstantForce()

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

See AddConstantForce(Vector2, Vector2?) and AddConstantCentralForce(Vector2?).

public Vector2 GetConstantForce()

Returns

Vector2

GetConstantTorque()

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

See AddConstantTorque(float).

public float GetConstantTorque()

Returns

float

GetContactCollider(int)

Returns the collider's Rid.

public Rid GetContactCollider(int contactIdx)

Parameters

contactIdx int

Returns

Rid

GetContactColliderId(int)

Returns the collider's object id.

public ulong GetContactColliderId(int contactIdx)

Parameters

contactIdx int

Returns

ulong

GetContactColliderObject(int)

Returns the collider object. This depends on how it was created (will return a scene node if such was used to create it).

public GodotObject GetContactColliderObject(int contactIdx)

Parameters

contactIdx int

Returns

GodotObject

GetContactColliderPosition(int)

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

public Vector2 GetContactColliderPosition(int contactIdx)

Parameters

contactIdx int

Returns

Vector2

GetContactColliderShape(int)

Returns the collider's shape index.

public int GetContactColliderShape(int contactIdx)

Parameters

contactIdx int

Returns

int

GetContactColliderVelocityAtPosition(int)

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

public Vector2 GetContactColliderVelocityAtPosition(int contactIdx)

Parameters

contactIdx int

Returns

Vector2

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 ContactMonitor.

public int GetContactCount()

Returns

int

GetContactImpulse(int)

Returns the impulse created by the contact.

public Vector2 GetContactImpulse(int contactIdx)

Parameters

contactIdx int

Returns

Vector2

GetContactLocalNormal(int)

Returns the local normal at the contact point.

public Vector2 GetContactLocalNormal(int contactIdx)

Parameters

contactIdx int

Returns

Vector2

GetContactLocalPosition(int)

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

public Vector2 GetContactLocalPosition(int contactIdx)

Parameters

contactIdx int

Returns

Vector2

GetContactLocalShape(int)

Returns the local shape index of the collision.

public int GetContactLocalShape(int contactIdx)

Parameters

contactIdx int

Returns

int

GetContactLocalVelocityAtPosition(int)

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

public Vector2 GetContactLocalVelocityAtPosition(int contactIdx)

Parameters

contactIdx int

Returns

Vector2

GetSpaceState()

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

public PhysicsDirectSpaceState2D GetSpaceState()

Returns

PhysicsDirectSpaceState2D

GetVelocityAtLocalPosition(Vector2)

Returns the body's velocity at the given relative position, including both translation and rotation.

public Vector2 GetVelocityAtLocalPosition(Vector2 localPosition)

Parameters

localPosition Vector2

Returns

Vector2

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

IntegrateForces()

Calls the built-in force integration code.

public void IntegrateForces()

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

SetConstantForce(Vector2)

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

See AddConstantForce(Vector2, Vector2?) and AddConstantCentralForce(Vector2?).

public void SetConstantForce(Vector2 force)

Parameters

force Vector2

SetConstantTorque(float)

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

See AddConstantTorque(float).

public void SetConstantTorque(float torque)

Parameters

torque float