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
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
CenterOfMassLocal
The body's center of mass position in the body's local coordinate system.
public Vector3 CenterOfMassLocal { get; }
Property Value
InverseInertia
The inverse of the inertia of the body.
public Vector3 InverseInertia { get; }
Property Value
InverseInertiaTensor
The inverse of the inertia tensor of the body.
public Basis InverseInertiaTensor { get; }
Property Value
InverseMass
The inverse of the mass of the body.
public float InverseMass { get; }
Property Value
LinearVelocity
The body's linear velocity in units per second.
public Vector3 LinearVelocity { get; set; }
Property Value
PrincipalInertiaAxes
public Basis PrincipalInertiaAxes { get; }
Property Value
Sleeping
If true
, this body is currently sleeping (not active).
public bool Sleeping { get; set; }
Property Value
Step
The timestep (delta) used for the simulation.
public float Step { get; }
Property Value
TotalAngularDamp
The rate at which the body stops rotating, if there are not any other forces moving it.
public float TotalAngularDamp { get; }
Property Value
TotalGravity
The total gravity vector being currently applied to this body.
public Vector3 TotalGravity { get; }
Property Value
TotalLinearDamp
The rate at which the body stops moving, if there are not any other forces moving it.
public float TotalLinearDamp { get; }
Property Value
Transform
The body's transformation matrix.
public Transform3D Transform { get; set; }
Property Value
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
Vector3position
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
Vector3position
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
Vector3position
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
GetConstantTorque()
Returns the body's total constant rotational forces applied during each physics update.
public Vector3 GetConstantTorque()
Returns
GetContactCollider(int)
Returns the collider's Rid.
public Rid GetContactCollider(int contactIdx)
Parameters
contactIdx
int
Returns
GetContactColliderId(int)
Returns the collider's object id.
public ulong GetContactColliderId(int contactIdx)
Parameters
contactIdx
int
Returns
GetContactColliderObject(int)
Returns the collider object.
public GodotObject GetContactColliderObject(int contactIdx)
Parameters
contactIdx
int
Returns
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
GetContactColliderShape(int)
Returns the collider's shape index.
public int GetContactColliderShape(int contactIdx)
Parameters
contactIdx
int
Returns
GetContactColliderVelocityAtPosition(int)
Returns the linear velocity vector at the collider's contact point.
public Vector3 GetContactColliderVelocityAtPosition(int contactIdx)
Parameters
contactIdx
int
Returns
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
GetContactImpulse(int)
Impulse created by the contact.
public Vector3 GetContactImpulse(int contactIdx)
Parameters
contactIdx
int
Returns
GetContactLocalNormal(int)
Returns the local normal at the contact point.
public Vector3 GetContactLocalNormal(int contactIdx)
Parameters
contactIdx
int
Returns
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
GetContactLocalShape(int)
Returns the local shape index of the collision.
public int GetContactLocalShape(int contactIdx)
Parameters
contactIdx
int
Returns
GetContactLocalVelocityAtPosition(int)
Returns the linear velocity vector at the body's contact point.
public Vector3 GetContactLocalVelocityAtPosition(int contactIdx)
Parameters
contactIdx
int
Returns
GetSpaceState()
Returns the current state of the space, useful for queries.
public PhysicsDirectSpaceState3D GetSpaceState()
Returns
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
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_nameName of the method to check for.
Returns
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_nameName of the signal to check for.
Returns
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_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
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.
public void SetConstantTorque(Vector3 torque)
Parameters
torque
Vector3