Table of Contents

Class RigidBody3D

A 3D physics body that is moved by a physics simulation.

Inheritance
RigidBody3D
Derived

Remarks

RigidBody3D implements full 3D physics. It cannot be controlled directly, instead, you must apply forces to it (gravity, impulses, etc.), and the physics simulation will calculate the resulting movement, rotation, react to collisions, and affect other physics bodies in its path.

The body's behavior can be adjusted via lock_rotation, freeze, and freeze_mode. By changing various properties of the object, such as mass, you can control how the physics simulation acts on it.

A rigid body will always maintain its shape and size, even when forces are applied to it. It is useful for objects that can be interacted with in an environment, such as a tree that can be knocked over or a stack of crates that can be pushed around.

If you need to override the default physics behavior, you can write a custom force integration function. See custom_integrator.

Note: Changing the 3D transform or linear_velocity of a RigidBody3D very often may lead to some unpredictable behaviors. If you need to directly affect the body, prefer RigidBody3D._integrate_forces as it allows you to directly access the physics state.

See Also

Properties

angular_damp

Damps the body's rotation. By default, the body will use the physics/3d/default_angular_damp project setting or any value override set by an Area3D the body is in. Depending on angular_damp_mode, you can set angular_damp to be added to or to replace the body's damping value.

See physics/3d/default_angular_damp for more details about damping.

var angular_damp : float = 0.0

Property Value

float

Remarks

  • void set_angular_damp(float value)
  • float get_angular_damp

angular_damp_mode

Defines how angular_damp is applied. See DampMode for possible values.

var angular_damp_mode : int = 0

Property Value

int

Remarks

  • void set_angular_damp_mode(int value)
  • int get_angular_damp_mode

angular_velocity

The RigidBody3D's rotational velocity in radians per second.

var angular_velocity : Vector3 = Vector3(0, 0, 0)

Property Value

Vector3

Remarks

  • void set_angular_velocity(Vector3 value)
  • Vector3 get_angular_velocity

can_sleep

If true, the body can enter sleep mode when there is no movement. See sleeping.

var can_sleep : bool = true

Property Value

bool

Remarks

  • void set_can_sleep(bool value)
  • bool is_able_to_sleep

center_of_mass

The body's custom center of mass, relative to the body's origin position, when center_of_mass_mode is set to RigidBody3D.CENTER_OF_MASS_MODE_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 center_of_mass_mode is set to RigidBody3D.CENTER_OF_MASS_MODE_AUTO (default value), the center of mass is automatically computed.

var center_of_mass : Vector3 = Vector3(0, 0, 0)

Property Value

Vector3

Remarks

center_of_mass_mode

Defines the way the body's center of mass is set. See CenterOfMassMode for possible values.

var center_of_mass_mode : int = 0

Property Value

int

Remarks

  • void set_center_of_mass_mode(int value)
  • int get_center_of_mass_mode

constant_force

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

See RigidBody3D.add_constant_force and RigidBody3D.add_constant_central_force.

var constant_force : Vector3 = Vector3(0, 0, 0)

Property Value

Vector3

Remarks

constant_torque

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

See RigidBody3D.add_constant_torque.

var constant_torque : Vector3 = Vector3(0, 0, 0)

Property Value

Vector3

Remarks

contact_monitor

If true, the RigidBody3D will emit signals when it collides with another body.

Note: By default the maximum contacts reported is set to 0, meaning nothing will be recorded, see max_contacts_reported.

var contact_monitor : bool = false

Property Value

bool

Remarks

  • void set_contact_monitor(bool value)
  • bool is_contact_monitor_enabled

continuous_cd

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.

var continuous_cd : bool = false

Property Value

bool

Remarks

  • void set_use_continuous_collision_detection(bool value)
  • bool is_using_continuous_collision_detection

custom_integrator

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._integrate_forces method, if that virtual method is overridden.

Setting this property will call the method PhysicsServer3D.body_set_omit_force_integration internally.

var custom_integrator : bool = false

Property Value

bool

Remarks

  • void set_use_custom_integrator(bool value)
  • bool is_using_custom_integrator

freeze

If true, the body is frozen. Gravity and forces are not applied anymore.

See freeze_mode to set the body's behavior when frozen.

For a body that is always frozen, use StaticBody3D or AnimatableBody3D instead.

var freeze : bool = false

Property Value

bool

Remarks

  • void set_freeze_enabled(bool value)
  • bool is_freeze_enabled

freeze_mode

The body's freeze mode. Can be used to set the body's behavior when freeze is enabled. See FreezeMode for possible values.

For a body that is always frozen, use StaticBody3D or AnimatableBody3D instead.

var freeze_mode : int = 0

Property Value

int

Remarks

  • void set_freeze_mode(int value)
  • int get_freeze_mode

gravity_scale

This is multiplied by 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.

var gravity_scale : float = 1.0

Property Value

float

Remarks

  • void set_gravity_scale(float value)
  • float get_gravity_scale

inertia

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 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.

@onready var ball = $Ball

func get_ball_inertia():
    return PhysicsServer3D.body_get_direct_state(ball.get_rid()).inverse_inertia.inverse()

var inertia : Vector3 = Vector3(0, 0, 0)

Property Value

Vector3

Remarks

linear_damp

Damps the body's movement. By default, the body will use the physics/3d/default_linear_damp project setting or any value override set by an Area3D the body is in. Depending on linear_damp_mode, you can set linear_damp to be added to or to replace the body's damping value.

See physics/3d/default_linear_damp for more details about damping.

var linear_damp : float = 0.0

Property Value

float

Remarks

  • void set_linear_damp(float value)
  • float get_linear_damp

linear_damp_mode

Defines how linear_damp is applied. See DampMode for possible values.

var linear_damp_mode : int = 0

Property Value

int

Remarks

  • void set_linear_damp_mode(int value)
  • int get_linear_damp_mode

linear_velocity

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._integrate_forces as your process loop for precise control of the body state.

var linear_velocity : Vector3 = Vector3(0, 0, 0)

Property Value

Vector3

Remarks

lock_rotation

If true, the body cannot rotate. Gravity and forces only apply linear movement.

var lock_rotation : bool = false

Property Value

bool

Remarks

  • void set_lock_rotation_enabled(bool value)
  • bool is_lock_rotation_enabled

mass

The body's mass.

var mass : float = 1.0

Property Value

float

Remarks

max_contacts_reported

The maximum number of contacts that will be recorded. Requires a value greater than 0 and contact_monitor to be set to true to start to register contacts. Use get_contact_count to retrieve the count or get_colliding_bodies 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).

var max_contacts_reported : int = 0

Property Value

int

Remarks

  • void set_max_contacts_reported(int value)
  • int get_max_contacts_reported

physics_material_override

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.

var physics_material_override : PhysicsMaterial

Property Value

PhysicsMaterial

Remarks

sleeping

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.apply_impulse or RigidBody3D.apply_force methods.

var sleeping : bool = false

Property Value

bool

Remarks

  • void set_sleeping(bool value)
  • bool is_sleeping

Methods

_integrate_forces(PhysicsDirectBodyState3D)

Qualifiers: virtual

Called during physics processing, allowing you to read and safely modify the simulation state for the object. By default, it is called before the standard force integration, but the custom_integrator property allows you to disable the standard force integration and do fully custom force integration for a body.

void _integrate_forces(PhysicsDirectBodyState3D state)

Parameters

state PhysicsDirectBodyState3D

add_constant_central_force(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 RigidBody3D.add_constant_force at the body's center of mass.

void add_constant_central_force(Vector3 force)

Parameters

force Vector3

add_constant_force(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.

void add_constant_force(Vector3 force, Vector3 position)

Parameters

force Vector3
position Vector3

add_constant_torque(Vector3)

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

void add_constant_torque(Vector3 torque)

Parameters

torque Vector3

apply_central_force(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 RigidBody3D.apply_force at the body's center of mass.

void apply_central_force(Vector3 force)

Parameters

force Vector3

apply_central_impulse(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 RigidBody3D.apply_impulse at the body's center of mass.

void apply_central_impulse(Vector3 impulse)

Parameters

impulse Vector3

apply_force(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.

void apply_force(Vector3 force, Vector3 position)

Parameters

force Vector3
position Vector3

apply_impulse(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.

void apply_impulse(Vector3 impulse, Vector3 position)

Parameters

impulse Vector3
position Vector3

apply_torque(Vector3)

Applies a rotational force without affecting position. A force is time dependent and meant to be applied every physics update.

Note: inertia is required for this to work. To have inertia, an active CollisionShape3D must be a child of the node, or you can manually set inertia.

void apply_torque(Vector3 torque)

Parameters

torque Vector3

apply_torque_impulse(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: inertia is required for this to work. To have inertia, an active CollisionShape3D must be a child of the node, or you can manually set inertia.

void apply_torque_impulse(Vector3 impulse)

Parameters

impulse Vector3

get_colliding_bodies

Qualifiers: const

Returns a list of the bodies colliding with this one. Requires contact_monitor to be set to true and max_contacts_reported 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.

Node3D[] get_colliding_bodies

get_contact_count

Qualifiers: const

Returns the number of contacts this body has with other bodies. By default, this returns 0 unless bodies are configured to monitor contacts (see contact_monitor).

Note: To retrieve the colliding bodies, use get_colliding_bodies.

int get_contact_count

get_inverse_inertia_tensor

Qualifiers: const

Returns the inverse inertia tensor basis. This is used to calculate the angular acceleration resulting from a torque applied to the RigidBody3D.

Basis get_inverse_inertia_tensor

set_axis_velocity(Vector3)

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.

void set_axis_velocity(Vector3 axis_velocity)

Parameters

axis_velocity Vector3

Events

body_entered(Node)

Emitted when a collision with another PhysicsBody3D or GridMap occurs. Requires contact_monitor to be set to true and max_contacts_reported to be set high enough to detect all the collisions. GridMaps are detected if the MeshLibrary has Collision Shape3Ds.

body the Node, if it exists in the tree, of the other PhysicsBody3D or GridMap.

signal body_entered(Node body)

Parameters

body Node

body_exited(Node)

Emitted when the collision with another PhysicsBody3D or GridMap ends. Requires contact_monitor to be set to true and max_contacts_reported to be set high enough to detect all the collisions. GridMaps are detected if the MeshLibrary has Collision Shape3Ds.

body the Node, if it exists in the tree, of the other PhysicsBody3D or GridMap.

signal body_exited(Node body)

Parameters

body Node

body_shape_entered(RID, Node, int, int)

Emitted when one of this RigidBody3D's Shape3Ds collides with another PhysicsBody3D or GridMap's Shape3Ds. Requires contact_monitor to be set to true and max_contacts_reported 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 Node, 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)).

signal body_shape_entered(RID body_rid, Node body, int body_shape_index, int local_shape_index)

Parameters

body_rid RID
body Node
body_shape_index int
local_shape_index int

body_shape_exited(RID, Node, int, int)

Emitted when the collision between one of this RigidBody3D's Shape3Ds and another PhysicsBody3D or GridMap's Shape3Ds ends. Requires contact_monitor to be set to true and max_contacts_reported 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 Node, 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)).

signal body_shape_exited(RID body_rid, Node body, int body_shape_index, int local_shape_index)

Parameters

body_rid RID
body Node
body_shape_index int
local_shape_index int

sleeping_state_changed

Emitted when the physics engine changes the body's sleeping state.

Note: Changing the value 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.

signal sleeping_state_changed