Table of Contents

Class PhysicsDirectBodyState3D

Namespace
Godot
Assembly
GodotSharp.dll

Provides direct access to a physics body in the PhysicsServer3D, allowing safe changes to physics properties. This object is passed via the direct state callback of RigidBody3D, and is intended for changing the direct state of that body. See _IntegrateForces(PhysicsDirectBodyState3D).

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

Properties

AngularVelocity

The body's rotational velocity in radians per second.

public Vector3 AngularVelocity { get; set; }

Property Value

Vector3

CenterOfMass

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

public Vector3 CenterOfMass { get; }

Property Value

Vector3

CenterOfMassLocal

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

public Vector3 CenterOfMassLocal { get; }

Property Value

Vector3

InverseInertia

The inverse of the inertia of the body.

public Vector3 InverseInertia { get; }

Property Value

Vector3

InverseInertiaTensor

The inverse of the inertia tensor of the body.

public Basis InverseInertiaTensor { get; }

Property Value

Basis

InverseMass

The inverse of the mass of the body.

public float InverseMass { get; }

Property Value

float

LinearVelocity

The body's linear velocity in units per second.

public Vector3 LinearVelocity { get; set; }

Property Value

Vector3

PrincipalInertiaAxes

public Basis PrincipalInertiaAxes { get; }

Property Value

Basis

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 Vector3 TotalGravity { get; }

Property Value

Vector3

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 Transform3D Transform { get; set; }

Property Value

Transform3D

Methods

AddConstantCentralForce(Vector3?)

Adds a constant directional force without affecting rotation that keeps being applied over time until cleared with constant_force = Vector3(0, 0, 0).

This is equivalent to using AddConstantForce(Vector3, Vector3?) at the body's center of mass.

public void AddConstantCentralForce(Vector3? force = null)

Parameters

force Vector3?

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

AddConstantForce(Vector3, Vector3?)

Adds a constant positioned force to the body that keeps being applied over time until cleared with constant_force = Vector3(0, 0, 0).

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

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

Parameters

force Vector3
position Vector3?

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

AddConstantTorque(Vector3)

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

public void AddConstantTorque(Vector3 torque)

Parameters

torque Vector3

ApplyCentralForce(Vector3?)

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

public void ApplyCentralForce(Vector3? force = null)

Parameters

force Vector3?

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

ApplyCentralImpulse(Vector3?)

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

public void ApplyCentralImpulse(Vector3? impulse = null)

Parameters

impulse Vector3?

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

ApplyForce(Vector3, Vector3?)

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(Vector3 force, Vector3? position = null)

Parameters

force Vector3
position Vector3?

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

ApplyImpulse(Vector3, Vector3?)

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(Vector3 impulse, Vector3? position = null)

Parameters

impulse Vector3
position Vector3?

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

ApplyTorque(Vector3)

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 CollisionShape3D must be a child of the node, or you can manually set InverseInertia.

public void ApplyTorque(Vector3 torque)

Parameters

torque Vector3

ApplyTorqueImpulse(Vector3)

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 CollisionShape3D must be a child of the node, or you can manually set InverseInertia.

public void ApplyTorqueImpulse(Vector3 impulse)

Parameters

impulse Vector3

GetConstantForce()

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

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

public Vector3 GetConstantForce()

Returns

Vector3

GetConstantTorque()

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

See AddConstantTorque(Vector3).

public Vector3 GetConstantTorque()

Returns

Vector3

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.

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 Vector3 GetContactColliderPosition(int contactIdx)

Parameters

contactIdx int

Returns

Vector3

GetContactColliderShape(int)

Returns the collider's shape index.

public int GetContactColliderShape(int contactIdx)

Parameters

contactIdx int

Returns

int

GetContactColliderVelocityAtPosition(int)

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

public Vector3 GetContactColliderVelocityAtPosition(int contactIdx)

Parameters

contactIdx int

Returns

Vector3

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)

Impulse created by the contact.

public Vector3 GetContactImpulse(int contactIdx)

Parameters

contactIdx int

Returns

Vector3

GetContactLocalNormal(int)

Returns the local normal at the contact point.

public Vector3 GetContactLocalNormal(int contactIdx)

Parameters

contactIdx int

Returns

Vector3

GetContactLocalPosition(int)

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

public Vector3 GetContactLocalPosition(int contactIdx)

Parameters

contactIdx int

Returns

Vector3

GetContactLocalShape(int)

Returns the local shape index of the collision.

public int GetContactLocalShape(int contactIdx)

Parameters

contactIdx int

Returns

int

GetContactLocalVelocityAtPosition(int)

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

public Vector3 GetContactLocalVelocityAtPosition(int contactIdx)

Parameters

contactIdx int

Returns

Vector3

GetSpaceState()

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

public PhysicsDirectSpaceState3D GetSpaceState()

Returns

PhysicsDirectSpaceState3D

GetVelocityAtLocalPosition(Vector3)

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

public Vector3 GetVelocityAtLocalPosition(Vector3 localPosition)

Parameters

localPosition Vector3

Returns

Vector3

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(Vector3)

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

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

public void SetConstantForce(Vector3 force)

Parameters

force Vector3

SetConstantTorque(Vector3)

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

See AddConstantTorque(Vector3).

public void SetConstantTorque(Vector3 torque)

Parameters

torque Vector3