Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

RigidBody3D

Inherits: PhysicsBody3D < CollisionObject3D < Node3D < Node < Object

Inherited By: VehicleBody3D

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

Description

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 _integrate_forces as it allows you to directly access the physics state.

Tutorials

Properties

float

angular_damp

0.0

DampMode

angular_damp_mode

0

Vector3

angular_velocity

Vector3(0, 0, 0)

bool

can_sleep

true

Vector3

center_of_mass

Vector3(0, 0, 0)

CenterOfMassMode

center_of_mass_mode

0

Vector3

constant_force

Vector3(0, 0, 0)

Vector3

constant_torque

Vector3(0, 0, 0)

bool

contact_monitor

false

bool

continuous_cd

false

bool

custom_integrator

false

bool

freeze

false

FreezeMode

freeze_mode

0

float

gravity_scale

1.0

Vector3

inertia

Vector3(0, 0, 0)

float

linear_damp

0.0

DampMode

linear_damp_mode

0

Vector3

linear_velocity

Vector3(0, 0, 0)

bool

lock_rotation

false

float

mass

1.0

int

max_contacts_reported

0

PhysicsMaterial

physics_material_override

bool

sleeping

false

Methods

void

_integrate_forces ( PhysicsDirectBodyState3D state ) virtual

void

add_constant_central_force ( Vector3 force )

void

add_constant_force ( Vector3 force, Vector3 position=Vector3(0, 0, 0) )

void

add_constant_torque ( Vector3 torque )

void

apply_central_force ( Vector3 force )

void

apply_central_impulse ( Vector3 impulse )

void

apply_force ( Vector3 force, Vector3 position=Vector3(0, 0, 0) )

void

apply_impulse ( Vector3 impulse, Vector3 position=Vector3(0, 0, 0) )

void

apply_torque ( Vector3 torque )

void

apply_torque_impulse ( Vector3 impulse )

Node3D[]

get_colliding_bodies ( ) const

int

get_contact_count ( ) const

Basis

get_inverse_inertia_tensor ( ) const

void

set_axis_velocity ( Vector3 axis_velocity )


Signals

body_entered ( Node body )

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.


body_exited ( Node body )

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.


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

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


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

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


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.


Enumerations

enum FreezeMode:

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

FreezeMode FREEZE_MODE_KINEMATIC = 1

Kinematic body freeze mode. Similar to FREEZE_MODE_STATIC, but collides with other bodies along its path when moved. Useful for a frozen body that needs to be animated.


enum CenterOfMassMode:

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

CenterOfMassMode CENTER_OF_MASS_MODE_CUSTOM = 1

In this mode, the body's center of mass is set through center_of_mass. Defaults to the body's origin position.


enum DampMode:

DampMode DAMP_MODE_COMBINE = 0

In this mode, the body's damping value is added to any value set in areas or the default value.

DampMode DAMP_MODE_REPLACE = 1

In this mode, the body's damping value replaces any value set in areas or the default value.


Property Descriptions

float angular_damp = 0.0

  • void set_angular_damp ( float value )

  • float get_angular_damp ( )

Damps the body's rotation. By default, the body will use the Default Angular Damp in Project > Project Settings > Physics > 3d 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 ProjectSettings.physics/3d/default_angular_damp for more details about damping.


DampMode angular_damp_mode = 0

  • void set_angular_damp_mode ( DampMode value )

  • DampMode get_angular_damp_mode ( )

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


Vector3 angular_velocity = Vector3(0, 0, 0)

  • void set_angular_velocity ( Vector3 value )

  • Vector3 get_angular_velocity ( )

The RigidBody3D's rotational velocity in radians per second.


bool can_sleep = true

  • void set_can_sleep ( bool value )

  • bool is_able_to_sleep ( )

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


Vector3 center_of_mass = Vector3(0, 0, 0)

  • void set_center_of_mass ( Vector3 value )

  • Vector3 get_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 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 CENTER_OF_MASS_MODE_AUTO (default value), the center of mass is automatic