RigidBody3D
A 3D dynamic body driven by forces and contacts.
RigidBody3D receives motion from the physics integrator. Use forces for thrust and impulses for one-off pushes. Repeated Position/Rotation writes in _Process compete with simulation. Request a controlled reset through _IntegrateForces and modify PhysicsDirectBodyState.
BodyEntered requires ContactMonitor and a positive MaxContactsReported. Sleeping, Freeze and shape Disabled differ. CustomIntegrator disables ordinary force integration, not every contact. The example checks falling, impulse, reset and freeze, not every stack/speed/platform.
Declarations checked against C# SDK 1.0.0. Expand a name to see declarations and documentation.
Constructors1
RigidBody3DConstructor
public RigidBody3D();Properties23
AngularDampProperty
public float AngularDamp { get; set; }Damps the body's rotation. By default, the body will use the ProjectSettings.physics/3d/default_angular_damp project setting or any value override set by an Area3D the body is in. Depending on RigidBody3D.AngularDampMode, you can set RigidBody3D.AngularDamp to be added to or to replace the body's damping value.
See ProjectSettings.physics/3d/default_angular_damp for more details about damping.
AngularDampModeProperty
public RigidBody3D.DampMode AngularDampMode { get; set; }Defines how RigidBody3D.AngularDamp is applied.
AngularVelocityProperty
public Vector3 AngularVelocity { get; set; }The RigidBody3D's rotational velocity in radians per second.
CanSleepProperty
public bool CanSleep { get; set; }If true, the body can enter sleep mode when there is no movement. See RigidBody3D.Sleeping.
CenterOfMassProperty
public Vector3 CenterOfMass { get; set; }The body's custom center of mass, relative to the body's origin position, when RigidBody3D.CenterOfMassMode is set to RigidBody3D.CenterOfMassModeEnum.Custom. This is the balanced point of the body, where applied forces only cause linear acceleration. Applying forces outside of the center of mass causes angular acceleration.
When RigidBody3D.CenterOfMassMode is set to RigidBody3D.CenterOfMassModeEnum.Auto (default value), the center of mass is automatically determined, but this does not update the value of RigidBody3D.CenterOfMass.
CenterOfMassModeProperty
public RigidBody3D.CenterOfMassModeEnum CenterOfMassMode { get; set; }Defines the way the body's center of mass is set.
ConstantForceProperty
public Vector3 ConstantForce { get; set; }The body's total constant positional forces applied during each physics update.
See RigidBody3D.AddConstantForce and RigidBody3D.AddConstantCentralForce.
ConstantTorqueProperty
public Vector3 ConstantTorque { get; set; }The body's total constant rotational forces applied during each physics update.
See RigidBody3D.AddConstantTorque.
ContactMonitorProperty
public bool ContactMonitor { get; set; }Enables body contact monitoring. Signals also need MaxContactsReported > 0 and actual contact between suitable shapes, not arbitrary visual overlap.
ContinuousCdProperty
public bool ContinuousCd { get; set; }If true, continuous collision detection is used.
Continuous collision detection tries to predict where a moving body will collide, instead of moving it and correcting its movement if it collided. Continuous collision detection is more precise, and misses fewer impacts by small, fast-moving objects. Not using continuous collision detection is faster to compute, but can miss small, fast-moving objects.
CustomIntegratorProperty
public bool CustomIntegrator { get; set; }If true, the standard force integration (like gravity or damping) will be disabled for this body. Other than collision response, the body will only move as determined by the RigidBody3D._IntegrateForces method, if that virtual method is overridden.
Setting this property will call the method PhysicsServer3D.BodySetOmitForceIntegration internally.
FreezeProperty
public bool Freeze { get; set; }If true, the body is frozen. Gravity and forces are not applied anymore.
See RigidBody3D.FreezeMode to set the body's behavior when frozen.
Note: For a body that is always frozen, use StaticBody3D or AnimatableBody3D instead.
FreezeModeProperty
public RigidBody3D.FreezeModeEnum FreezeMode { get; set; }The body's freeze mode. Determines the body's behavior when RigidBody3D.Freeze is true.
Note: For a body that is always frozen, use StaticBody3D or AnimatableBody3D instead.
GravityScaleProperty
public float GravityScale { get; set; }This is multiplied by ProjectSettings.physics/3d/default_gravity to produce this body's gravity. For example, a value of 1.0 will apply normal gravity, 2.0 will apply double the gravity, and 0.5 will apply half the gravity to this body.
InertiaProperty
public Vector3 Inertia { get; set; }The body's moment of inertia. This is like mass, but for rotation: it determines how much torque it takes to rotate the body on each axis. The moment of inertia is usually computed automatically from the mass and the shapes, but this property allows you to set a custom value.
If set to Vector3.Zero, inertia is automatically computed (default value).
Note: This value does not change when inertia is automatically computed. Use PhysicsServer3D to get the computed inertia.
private RigidBody3D _ball;
public override void _Ready()
{
_ball = GetEntity<RigidBody3D>("Ball");
}
private Vector3 GetBallInertia()
{
return PhysicsServer3D.BodyGetDirectState(_ball.GetRid()).InverseInertia.Inverse();
}LinearDampProperty
public float LinearDamp { get; set; }Damps the body's movement. By default, the body will use the ProjectSettings.physics/3d/default_linear_damp project setting or any value override set by an Area3D the body is in. Depending on RigidBody3D.LinearDampMode, you can set RigidBody3D.LinearDamp to be added to or to replace the body's damping value.
See ProjectSettings.physics/3d/default_linear_damp for more details about damping.
LinearDampModeProperty
public RigidBody3D.DampMode LinearDampMode { get; set; }Defines how RigidBody3D.LinearDamp is applied.
LinearVelocityProperty
public Vector3 LinearVelocity { get; set; }The body's linear velocity in units per second. Can be used sporadically, but don't set this every frame, because physics may run in another thread and runs at a different granularity. Use RigidBody3D._IntegrateForces as your process loop for precise control of the body state.
LockRotationProperty
public bool LockRotation { get; set; }If true, the body cannot rotate. Gravity and forces only apply linear movement.
MassProperty
public float Mass { get; set; }The body's mass.
MaxContactsReportedProperty
public int MaxContactsReported { get; set; }The maximum number of contacts that will be recorded. Requires a value greater than 0 and RigidBody3D.ContactMonitor to be set to true to start to register contacts. Use RigidBody3D.GetContactCount to retrieve the count or RigidBody3D.GetCollidingBodies to retrieve bodies that have been collided with.
Note: The number of contacts is different from the number of collisions. Collisions between parallel edges will result in two contacts (one at each end), and collisions between parallel faces will result in four contacts (one at each corner).
PhysicsMaterialOverrideProperty
public PhysicsMaterial PhysicsMaterialOverride { get; set; }The physics material override for the body. If a material is assigned to this property, it will be used instead of any other physics material, such as an inherited one.
SleepingProperty
public bool Sleeping { get; set; }If true, the body will not move and will not calculate forces until woken up by another body through, for example, a collision, or by using the RigidBody3D.ApplyImpulse or RigidBody3D.ApplyForce methods.
Methods62
AddConstantCentralForcevoid
public void AddConstantCentralForce(Vector3 force);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 RigidBody3D.AddConstantForce at the body's center of mass.
| Name | Type | Default |
|---|---|---|
force | Vector3 | — |
AddConstantForcevoid
public void AddConstantForce(Vector3 force, Vector3? position = default);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.
| Name | Type | Default |
|---|---|---|
force | Vector3 | — |
position | Vector3? | default |
positionIf the parameter is null, then the default value is new Vector3(0.0f, 0.0f, 0.0f).
AddConstantTorquevoid
public void AddConstantTorque(Vector3 torque);Adds a constant rotational force without affecting position that keeps being applied over time until cleared with constant_torque = Vector3(0, 0, 0).
| Name | Type | Default |
|---|---|---|
torque | Vector3 | — |
ApplyCentralForcevoid
public void ApplyCentralForce(Vector3 force);Applies force for the current physics tick. Call on every required _PhysicsProcess for thrust; force is already integrated over time, so multiplying by delta again is incorrect.
| Name | Type | Default |
|---|---|---|
force | Vector3 | — |
ApplyCentralImpulsevoid
public void ApplyCentralImpulse(Vector3 impulse);Applies a one-off central impulse. Do not multiply by delta or call each frame for continuous thrust. Without constraints/damping, velocity change depends on impulse / mass.
| Name | Type | Default |
|---|---|---|
impulse | Vector3 | — |
ApplyForcevoid
public void ApplyForce(Vector3 force, Vector3? position = default);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.
| Name | Type | Default |
|---|---|---|
force | Vector3 | — |
position | Vector3? | default |
positionIf the parameter is null, then the default value is new Vector3(0.0f, 0.0f, 0.0f).
ApplyImpulsevoid
public void ApplyImpulse(Vector3 impulse, Vector3? position = default);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.
| Name | Type | Default |
|---|---|---|
impulse | Vector3 | — |
position | Vector3? | default |
positionIf the parameter is null, then the default value is new Vector3(0.0f, 0.0f, 0.0f).
ApplyTorquevoid
public void ApplyTorque(Vector3 torque);Applies a rotational force without affecting position. A force is time dependent and meant to be applied every physics update.
Note: RigidBody3D.Inertia is required for this to work. To have RigidBody3D.Inertia, an active CollisionShape3D must be a child of the node, or you can manually set RigidBody3D.Inertia.
| Name | Type | Default |
|---|---|---|
torque | Vector3 | — |
ApplyTorqueImpulsevoid
public void ApplyTorqueImpulse(Vector3 impulse);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: RigidBody3D.Inertia is required for this to work. To have RigidBody3D.Inertia, an active CollisionShape3D must be a child of the node, or you can manually set RigidBody3D.Inertia.
| Name | Type | Default |
|---|---|---|
impulse | Vector3 | — |
GetAngularDampfloat
public float GetAngularDamp();floatGetAngularDampModeRigidBody3D.DampMode
public RigidBody3D.DampMode GetAngularDampMode();RigidBody3D.DampModeGetAngularVelocityVector3
public Vector3 GetAngularVelocity();Vector3GetCenterOfMassVector3
public Vector3 GetCenterOfMass();Vector3GetCenterOfMassModeRigidBody3D.CenterOfMassModeEnum
public RigidBody3D.CenterOfMassModeEnum GetCenterOfMassMode();RigidBody3D.CenterOfMassModeEnumGetCollidingBodiesReckfell.Collections.Array<Entity3D>
public Reckfell.Collections.Array<Entity3D> GetCollidingBodies();Returns a list of the bodies colliding with this one. Requires RigidBody3D.ContactMonitor to be set to true and RigidBody3D.MaxContactsReported to be set high enough to detect all the collisions.
Note: The result of this test is not immediate after moving objects. For performance, list of collisions is updated once per frame and before the physics step. Consider using signals instead.
Reckfell.Collections.Array<Entity3D>GetConstantForceVector3
public Vector3 GetConstantForce();Vector3GetConstantTorqueVector3
public Vector3 GetConstantTorque();Vector3GetContactCountint
public int GetContactCount();Returns the number of contacts this body has with other bodies. By default, this returns 0 unless bodies are configured to monitor contacts (see RigidBody3D.ContactMonitor).
Note: To retrieve the colliding bodies, use RigidBody3D.GetCollidingBodies.
intGetFreezeModeRigidBody3D.FreezeModeEnum
public RigidBody3D.FreezeModeEnum GetFreezeMode();RigidBody3D.FreezeModeEnumGetGravityScalefloat
public float GetGravityScale();floatGetInertiaVector3
public Vector3 GetInertia();Vector3GetInverseInertiaTensorBasis
public Basis GetInverseInertiaTensor();Returns the inverse inertia tensor basis. This is used to calculate the angular acceleration resulting from a torque applied to the RigidBody3D.
BasisGetLinearDampfloat
public float GetLinearDamp();floatGetLinearDampModeRigidBody3D.DampMode
public RigidBody3D.DampMode GetLinearDampMode();RigidBody3D.DampModeGetLinearVelocityVector3
public Vector3 GetLinearVelocity();Vector3GetMassfloat
public float GetMass();floatGetMaxContactsReportedint
public int GetMaxContactsReported();intGetPhysicsMaterialOverridePhysicsMaterial
public PhysicsMaterial GetPhysicsMaterialOverride();PhysicsMaterialGetVelocityAtLocalPositionVector3
public Vector3 GetVelocityAtLocalPosition(Vector3 localPosition);Returns the body's velocity at the given relative position.
local_position is the offset from the body origin in global coordinates.
See also RigidBody3D.GetVelocityAtPosition.
| Name | Type | Default |
|---|---|---|
localPosition | Vector3 | — |
Vector3GetVelocityAtPositionVector3
public Vector3 GetVelocityAtPosition(Vector3 globalPoint);Returns the body's velocity at the given global position.
This is equivalent to get_velocity_at_local_position(global_point - global_position).
See also RigidBody3D.GetVelocityAtLocalPosition.
| Name | Type | Default |
|---|---|---|
globalPoint | Vector3 | — |
Vector3IsAbleToSleepbool
public bool IsAbleToSleep();boolIsContactMonitorEnabledbool
public bool IsContactMonitorEnabled();boolIsFreezeEnabledbool
public bool IsFreezeEnabled();boolIsLockRotationEnabledbool
public bool IsLockRotationEnabled();boolIsSleepingbool
public bool IsSleeping();boolIsUsingContinuousCollisionDetectionbool
public bool IsUsingContinuousCollisionDetection();boolIsUsingCustomIntegratorbool
public bool IsUsingCustomIntegrator();boolSetAngularDampvoid
public void SetAngularDamp(float angularDamp);| Name | Type | Default |
|---|---|---|
angularDamp | float | — |
SetAngularDampModevoid
public void SetAngularDampMode(RigidBody3D.DampMode angularDampMode);| Name | Type | Default |
|---|---|---|
angularDampMode | RigidBody3D.DampMode | — |
SetAngularVelocityvoid
public void SetAngularVelocity(Vector3 angularVelocity);| Name | Type | Default |
|---|---|---|
angularVelocity | Vector3 | — |
SetAxisVelocityvoid
public void SetAxisVelocity(Vector3 axisVelocity);Sets an axis velocity. The velocity in the given vector axis will be set as the given vector length. This is useful for jumping behavior.
| Name | Type | Default |
|---|---|---|
axisVelocity | Vector3 | — |
SetCanSleepvoid
public void SetCanSleep(bool ableToSleep);| Name | Type | Default |
|---|---|---|
ableToSleep | bool | — |
SetCenterOfMassvoid
public void SetCenterOfMass(Vector3 centerOfMass);| Name | Type | Default |
|---|---|---|
centerOfMass | Vector3 | — |
SetCenterOfMassModevoid
public void SetCenterOfMassMode(RigidBody3D.CenterOfMassModeEnum mode);| Name | Type | Default |
|---|---|---|
mode | RigidBody3D.CenterOfMassModeEnum | — |
SetConstantForcevoid
public void SetConstantForce(Vector3 force);| Name | Type | Default |
|---|---|---|
force | Vector3 | — |
SetConstantTorquevoid
public void SetConstantTorque(Vector3 torque);| Name | Type | Default |
|---|---|---|
torque | Vector3 | — |
SetContactMonitorvoid
public void SetContactMonitor(bool enabled);| Name | Type | Default |
|---|---|---|
enabled | bool | — |
SetFreezeEnabledvoid
public void SetFreezeEnabled(bool freezeMode);| Name | Type | Default |
|---|---|---|
freezeMode | bool | — |
SetFreezeModevoid
public void SetFreezeMode(RigidBody3D.FreezeModeEnum freezeMode);| Name | Type | Default |
|---|---|---|
freezeMode | RigidBody3D.FreezeModeEnum | — |
SetGravityScalevoid
public void SetGravityScale(float gravityScale);| Name | Type | Default |
|---|---|---|
gravityScale | float | — |
SetInertiavoid
public void SetInertia(Vector3 inertia);| Name | Type | Default |
|---|---|---|
inertia | Vector3 | — |
SetLinearDampvoid
public void SetLinearDamp(float linearDamp);| Name | Type | Default |
|---|---|---|
linearDamp | float | — |
SetLinearDampModevoid
public void SetLinearDampMode(RigidBody3D.DampMode linearDampMode);| Name | Type | Default |
|---|---|---|
linearDampMode | RigidBody3D.DampMode | — |
SetLinearVelocityvoid
public void SetLinearVelocity(Vector3 linearVelocity);| Name | Type | Default |
|---|---|---|
linearVelocity | Vector3 | — |
SetLockRotationEnabledvoid
public void SetLockRotationEnabled(bool lockRotation);| Name | Type | Default |
|---|---|---|
lockRotation | bool | — |
SetMassvoid
public void SetMass(float mass);| Name | Type | Default |
|---|---|---|
mass | float | — |
SetMaxContactsReportedvoid
public void SetMaxContactsReported(int amount);| Name | Type | Default |
|---|---|---|
amount | int | — |
SetPhysicsMaterialOverridevoid
public void SetPhysicsMaterialOverride(PhysicsMaterial physicsMaterialOverride);| Name | Type | Default |
|---|---|---|
physicsMaterialOverride | PhysicsMaterial | — |
SetSleepingvoid
public void SetSleeping(bool sleeping);| Name | Type | Default |
|---|---|---|
sleeping | bool | — |
SetUseContinuousCollisionDetectionvoid
public void SetUseContinuousCollisionDetection(bool enable);| Name | Type | Default |
|---|---|---|
enable | bool | — |
SetUseCustomIntegratorvoid
public void SetUseCustomIntegrator(bool enable);| Name | Type | Default |
|---|---|---|
enable | bool | — |
_IntegrateForcesvoid
public virtual void _IntegrateForces(PhysicsDirectBodyState3D state);A physics callback for controlled state modification. For teleporting, set state.Transform and explicitly clear required velocities. Do not substitute repeated Position writes in _Process for the integrator.
| Name | Type | Default |
|---|---|---|
state | PhysicsDirectBodyState3D | — |
Signals and events5
BodyEnteredEvent
public event RigidBody3D.BodyEnteredEventHandler BodyEntered;Emitted when a collision with another PhysicsBody3D or GridMap occurs. Requires RigidBody3D.ContactMonitor to be set to true and RigidBody3D.MaxContactsReported to be set high enough to detect all the collisions. GridMaps are detected if the MeshLibrary has Collision Shape3Ds.
body the Entity, if it exists in the tree, of the other PhysicsBody3D or GridMap.
| Name | Type | Default |
|---|---|---|
body | Entity | — |
BodyExitedEvent
public event RigidBody3D.BodyExitedEventHandler BodyExited;Emitted when the collision with another PhysicsBody3D or GridMap ends. Requires RigidBody3D.ContactMonitor to be set to true and RigidBody3D.MaxContactsReported to be set high enough to detect all the collisions. GridMaps are detected if the MeshLibrary has Collision Shape3Ds.
body the Entity, if it exists in the tree, of the other PhysicsBody3D or GridMap.
| Name | Type | Default |
|---|---|---|
body | Entity | — |
BodyShapeEnteredEvent
public event RigidBody3D.BodyShapeEnteredEventHandler BodyShapeEntered;Emitted when one of this RigidBody3D's Shape3Ds collides with another PhysicsBody3D or GridMap's Shape3Ds. Requires RigidBody3D.ContactMonitor to be set to true and RigidBody3D.MaxContactsReported to be set high enough to detect all the collisions. GridMaps are detected if the MeshLibrary has Collision Shape3Ds.
body_rid the Rid of the other PhysicsBody3D or MeshLibrary's CollisionObject3D used by the PhysicsServer3D.
body the Entity, if it exists in the tree, of the other PhysicsBody3D or GridMap.
body_shape_index the index of the Shape3D of the other PhysicsBody3D or GridMap used by the PhysicsServer3D. Get the CollisionShape3D node with body.shape_owner_get_owner(body.shape_find_owner(body_shape_index)).
local_shape_index the index of the Shape3D of this RigidBody3D used by the PhysicsServer3D. Get the CollisionShape3D node with self.shape_owner_get_owner(self.shape_find_owner(local_shape_index)).
| Name | Type | Default |
|---|---|---|
bodyRid | Rid | — |
body | Entity | — |
bodyShapeIndex | long | — |
localShapeIndex | long | — |
BodyShapeExitedEvent
public event RigidBody3D.BodyShapeExitedEventHandler BodyShapeExited;Emitted when the collision between one of this RigidBody3D's Shape3Ds and another PhysicsBody3D or GridMap's Shape3Ds ends. Requires RigidBody3D.ContactMonitor to be set to true and RigidBody3D.MaxContactsReported to be set high enough to detect all the collisions. GridMaps are detected if the MeshLibrary has Collision Shape3Ds.
body_rid the Rid of the other PhysicsBody3D or MeshLibrary's CollisionObject3D used by the PhysicsServer3D. GridMaps are detected if the Meshes have Shape3Ds.
body the Entity, if it exists in the tree, of the other PhysicsBody3D or GridMap.
body_shape_index the index of the Shape3D of the other PhysicsBody3D or GridMap used by the PhysicsServer3D. Get the CollisionShape3D node with body.shape_owner_get_owner(body.shape_find_owner(body_shape_index)).
local_shape_index the index of the Shape3D of this RigidBody3D used by the PhysicsServer3D. Get the CollisionShape3D node with self.shape_owner_get_owner(self.shape_find_owner(local_shape_index)).
| Name | Type | Default |
|---|---|---|
bodyRid | Rid | — |
body | Entity | — |
bodyShapeIndex | long | — |
localShapeIndex | long | — |
SleepingStateChangedEvent
public event Action SleepingStateChanged;Emitted when the physics engine changes the body's sleeping state.
Note: Changing the value RigidBody3D.Sleeping will not trigger this signal. It is only emitted if the sleeping state is changed by the physics engine or emit_signal("sleeping_state_changed") is used.
RigidBody3D.CenterOfMassModeEnum
| Value | Description |
|---|---|
Auto = 0 | In this mode, the body's center of mass is calculated automatically based on its shapes. This assumes that the shapes' origins are also their center of mass. |
Custom = 1 | In this mode, the body's center of mass is set through |
RigidBody3D.DampMode
| Value | Description |
|---|---|
Combine = 0 | In this mode, the body's damping value is added to any value set in areas or the default value. |
Replace = 1 | In this mode, the body's damping value replaces any value set in areas or the default value. |
RigidBody3D.FreezeModeEnum
| Value | Description |
|---|---|
Kinematic = 1 | Kinematic body freeze mode. Similar to |
Static = 0 | Static body freeze mode (default). The body is not affected by gravity and forces. It can be only moved by user code and doesn't collide with other bodies along its path. |