Direct access object to a physics body in the Physics2DServer.
    public abstract class Physics2DDirectBodyState : Object

Provides direct access to a physics body in the Physics2DServer, allowing safe changes to physics properties. This object is passed via the direct state callback of rigid/character bodies, and is intended for changing the direct state of that body. See RigidBody2D._IntegrateForces(Godot.Physics2DDirectBodyState).

Inheritance Chain


    public float AngularVelocity { get; set; }

The body’s rotational velocity.

    public float InverseInertia { get; }

The inverse of the inertia of the body.

    public float InverseMass { get; }

The inverse of the mass of the body.

    public Vector2 LinearVelocity { get; set; }

The body’s linear velocity.

    public bool Sleeping { get; set; }

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

    public float Step { get; }

The timestep (delta) used for the simulation.

    public float TotalAngularDamp { get; }

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

    public Vector2 TotalGravity { get; }

The total gravity vector being currently applied to this body.

    public float TotalLinearDamp { get; }

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

    public Transform2D Transform { get; set; }

The body’s transformation matrix.


    public void AddCentralForce(Vector2 force)

Adds a constant directional force without affecting rotation.

    public void AddForce(Vector2 offset, Vector2 force)

Adds a positioned force to the body. Both the force and the offset from the body origin are in global coordinates.

    public void AddTorque(float torque)

Adds a constant rotational force.

    public void ApplyCentralImpulse(Vector2 impulse)

Applies a directional impulse without affecting rotation.

    public void ApplyImpulse(Vector2 offset, Vector2 impulse)

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). The offset uses the rotation of the global coordinate system, but is centered at the object’s origin.

    public void ApplyTorqueImpulse(float impulse)

Applies a rotational impulse to the body.

    public float GetAngularVelocity()

Getter for AngularVelocity

    public RID GetContactCollider(int contactIdx)

Returns the collider’s RID.

    public int GetContactColliderId(int contactIdx)

Returns the collider’s object id.

    public Object 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).

    public Vector2 GetContactColliderPosition(int contactIdx)

Returns the contact position in the collider.

    public int GetContactColliderShape(int contactIdx)

Returns the collider’s shape index.

    public object GetContactColliderShapeMetadata(int contactIdx)

Returns the collided shape’s metadata. This metadata is different from Object.GetMeta(string), and is set with Physics2DServer.ShapeSetData(Godot.RID, object).

    public Vector2 GetContactColliderVelocityAtPosition(int contactIdx)

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

    public int GetContactCount()

Returns the number of contacts this body has with other bodies. Note that by default this returns 0 unless bodies are configured to log contacts. See RigidBody2D.ContactMonitor.

    public Vector2 GetContactLocalNormal(int contactIdx)

Returns the local normal at the contact point.

    public Vector2 GetContactLocalPosition(int contactIdx)

Returns the local position of the contact point.

    public int GetContactLocalShape(int contactIdx)

Returns the local shape index of the collision.

    public float GetInverseInertia()

Getter for InverseInertia

    public float GetInverseMass()

Getter for InverseMass

    public Vector2 GetLinearVelocity()

Getter for LinearVelocity

    public Physics2DDirectSpaceState GetSpaceState()

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

    public float GetStep()

Getter for Step

    public float GetTotalAngularDamp()

Getter for TotalAngularDamp

    public Vector2 GetTotalGravity()

Getter for TotalGravity

    public float GetTotalLinearDamp()

Getter for TotalLinearDamp

    public Transform2D GetTransform()

Getter for Transform

    public void IntegrateForces()

Calls the built-in force integration code.

    public bool IsSleeping()

Getter for Sleeping

    public void SetAngularVelocity(float velocity)

Setter for AngularVelocity

    public void SetLinearVelocity(Vector2 velocity)

Setter for LinearVelocity

    public void SetSleepState(bool enabled)

Setter for Sleeping

    public void SetTransform(Transform2D transform)

Setter for Transform