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
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
CenterOfMassLocal
The body's center of mass position in the body's local coordinate system.
public Vector2 CenterOfMassLocal { get; }
Property Value
InverseInertia
The inverse of the inertia of the body.
public float InverseInertia { 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 pixels per second.
public Vector2 LinearVelocity { get; set; }
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 Vector2 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 Transform2D Transform { get; set; }
Property Value
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
Vector2position
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
Vector2position
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
Vector2position
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
GetConstantTorque()
Returns the body's total constant rotational forces applied during each physics update.
public float 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. 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
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
GetContactColliderShape(int)
Returns the collider's shape index.
public int GetContactColliderShape(int contactIdx)
Parameters
contactIdx
int
Returns
GetContactColliderVelocityAtPosition(int)
Returns the velocity vector at the collider's contact point.
public Vector2 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)
Returns the impulse created by the contact.
public Vector2 GetContactImpulse(int contactIdx)
Parameters
contactIdx
int
Returns
GetContactLocalNormal(int)
Returns the local normal at the contact point.
public Vector2 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 Vector2 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 velocity vector at the body's contact point.
public Vector2 GetContactLocalVelocityAtPosition(int contactIdx)
Parameters
contactIdx
int
Returns
GetSpaceState()
Returns the current state of the space, useful for queries.
public PhysicsDirectSpaceState2D GetSpaceState()
Returns
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
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(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.
public void SetConstantTorque(float torque)
Parameters
torque
float