RigidBody

Inherits: PhysicsBody < CollisionObject < Spatial < Node < Object

Inherited By: VehicleBody

Cuerpo físico cuya posición se determina a través de la simulación física en el espacio 3D.

Descripción

This is the node that implements full 3D physics. This means that you do not control a RigidBody directly. Instead, you can apply forces to it (gravity, impulses, etc.), and the physics simulation will calculate the resulting movement, collision, bouncing, rotating, etc.

A RigidBody has 4 behavior modes: Rigid, Static, Character, and Kinematic.

Note: Don't change a RigidBody's position every frame or very often. Sporadic changes work fine, but physics runs at a different granularity (fixed Hz) than usual rendering (process callback) and maybe even in a separate thread, so changing this from a process loop may result in strange behavior. If you need to directly affect the body's state, use _integrate_forces, which allows you to directly access the physics state.

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

With Bullet physics (the default), the center of mass is the RigidBody3D center. With GodotPhysics, the center of mass is the average of the CollisionShape centers.

Tutoriales

Propiedades

float

angular_damp

-1.0

Vector3

angular_velocity

Vector3( 0, 0, 0 )

bool

axis_lock_angular_x

false

bool

axis_lock_angular_y

false

bool

axis_lock_angular_z

false

bool

axis_lock_linear_x

false

bool

axis_lock_linear_y

false

bool

axis_lock_linear_z

false

float

bounce

bool

can_sleep

true

bool

contact_monitor

false

int

contacts_reported

0

bool

continuous_cd

false

bool

custom_integrator

false

float

friction

float

gravity_scale

1.0

float

linear_damp

-1.0

Vector3

linear_velocity

Vector3( 0, 0, 0 )

float

mass

1.0

Mode

mode

0

PhysicsMaterial

physics_material_override

bool

sleeping

false

float

weight

9.8

Métodos

void

_integrate_forces ( PhysicsDirectBodyState state ) virtual

void

add_central_force ( Vector3 force )

void

add_force ( Vector3 force, Vector3 position )

void

add_torque ( Vector3 torque )

void

apply_central_impulse ( Vector3 impulse )

void

apply_impulse ( Vector3 position, Vector3 impulse )

void

apply_torque_impulse ( Vector3 impulse )

bool

get_axis_lock ( BodyAxis axis ) const

Array

get_colliding_bodies ( ) const

Basis

get_inverse_inertia_tensor ( )

void

set_axis_lock ( BodyAxis axis, bool lock )

void

set_axis_velocity ( Vector3 axis_velocity )

Señales

  • body_entered ( Node body )

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

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


  • body_exited ( Node body )

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

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


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

Emitted when one of this RigidBody's Shapes collides with another PhysicsBody or GridMap's Shapes. Requires contact_monitor to be set to true and contacts_reported to be set high enough to detect all the collisions. GridMaps are detected if the MeshLibrary has Collision Shapes.

body_rid the RID of the other PhysicsBody or MeshLibrary's CollisionObject used by the PhysicsServer.

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

body_shape_index the index of the Shape of the other PhysicsBody or GridMap used by the PhysicsServer. Get the CollisionShape node with body.shape_owner_get_owner(body_shape_index).

local_shape_index the index of the Shape of this RigidBody used by the PhysicsServer. Get the CollisionShape node with self.shape_owner_get_owner(local_shape_index).

Note: Bullet physics cannot identify the shape index when using a ConcavePolygonShape. Don't use multiple CollisionShapes when using a ConcavePolygonShape with Bullet physics if you need shape indices.


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

Emitted when the collision between one of this RigidBody's Shapes and another PhysicsBody or GridMap's Shapes ends. Requires contact_monitor to be set to true and contacts_reported to be set high enough to detect all the collisions. GridMaps are detected if the MeshLibrary has Collision Shapes.

body_rid the RID of the other PhysicsBody or MeshLibrary's CollisionObject used by the PhysicsServer. GridMaps are detected if the Meshes have Shapes.

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

body_shape_index the index of the Shape of the other PhysicsBody or GridMap used by the PhysicsServer. Get the CollisionShape node with body.shape_owner_get_owner(body_shape_index).

local_shape_index the index of the Shape of this RigidBody used by the PhysicsServer. Get the CollisionShape node with self.shape_owner_get_owner(local_shape_index).

Note: Bullet physics cannot identify the shape index when using a ConcavePolygonShape. Don't use multiple CollisionShapes when using a ConcavePolygonShape with Bullet physics if you need shape indices.


  • sleeping_state_changed ( )

Emitida cuando el motor físico cambia el estado de sueño del cuerpo.

Nota: Cambiar el valor sleeping no activará esta señal. Sólo se emite si el motor de física cambia el estado de sueño o si se utiliza emit_signal("sleeping_state_changed").

Enumeraciones

enum Mode:

  • MODE_RIGID = 0 --- Modo de cuerpo rígido. Este es el estado "natural" de un cuerpo rígido. Es afectado por fuerzas, y puede moverse, rotar y ser afectado por el código de usuario.

  • MODE_STATIC = 1 --- Static mode. The body behaves like a StaticBody, and can only move by user code.

  • MODE_CHARACTER = 2 --- Modo de cuerpo de personaje. Se comporta como un cuerpo rígido, pero no puede girar.

  • MODE_KINEMATIC = 3 --- Kinematic body mode. The body behaves like a KinematicBody, and can only move by user code.

Descripciones de Propiedades

Default

-1.0

Setter

set_angular_damp(value)

Getter

get_angular_damp()

Damps RigidBody's rotational forces.

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


Default

Vector3( 0, 0, 0 )

Setter

set_angular_velocity(value)

Getter

get_angular_velocity()

The body's rotational velocity in axis-angle format. The magnitude of the vector is the rotation rate in radians per second.


  • bool axis_lock_angular_x

Default

false

Setter

set_axis_lock(value)

Getter

get_axis_lock()

Bloquea la rotación del cuerpo en el eje X.


  • bool axis_lock_angular_y

Default

false

Setter

set_axis_lock(value)

Getter

get_axis_lock()

Bloquea la rotación del cuerpo en el eje Y.


  • bool axis_lock_angular_z

Default

false

Setter

set_axis_lock(value)

Getter

get_axis_lock()

Bloquea la rotación del cuerpo en el eje Z.


  • bool axis_lock_linear_x

Default

false

Setter

set_axis_lock(value)

Getter

get_axis_lock()

Bloquea el movimiento del cuerpo en el eje X.


  • bool axis_lock_linear_y

Default

false

Setter

set_axis_lock(value)

Getter

get_axis_lock()

Bloquea el movimiento del cuerpo en el eje Y.


  • bool axis_lock_linear_z

Default

false

Setter

set_axis_lock(value)

Getter

get_axis_lock()

Bloquea el movimiento del cuerpo en el eje Z.


Setter

set_bounce(value)

Getter

get_bounce()

The body's bounciness. Values range from 0 (no bounce) to 1 (full bounciness).

Deprecated, use PhysicsMaterial.bounce instead via physics_material_override.


Default

true

Setter

set_can_sleep(value)

Getter

is_able_to_sleep()

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

Note: A RigidBody3D will never enter sleep mode automatically if its mode is MODE_CHARACTER. It can still be put to sleep manually by setting its sleeping property to true.


  • bool contact_monitor

Default

false

Setter

set_contact_monitor(value)

Getter

is_contact_monitor_enabled()

If true, the RigidBody will emit signals when it collides with another RigidBody. See also contacts_reported.


  • int contacts_reported

Default

0

Setter

set_max_contacts_reported(value)

Getter

get_max_contacts_reported()

El número máximo de contactos que serán reportados. Requiere que contact_monitor sea true.

Nota: El número de contactos es diferente al número de colisiones. Las colisiones entre bordes paralelos resultará en dos contactos (uno en cada extremo), y las colisiones entre caras paralelas resultará en cuatro contactos (uno en cada esquina).


  • bool continuous_cd

Default

false

Setter

set_use_continuous_collision_detection(value)

Getter

is_using_continuous_collision_detection()

Si true, se utiliza la detección continua de colisiones.

La detección de colisión continua trata de predecir dónde colisionará un cuerpo en movimiento, en lugar de moverlo y corregir su movimiento si colisionara. La detección de colisión continua es más precisa, y pierde menos impactos de objetos pequeños y de movimiento rápido. No usar la detección de colisión continua es más rápido de calcular, pero puede pasar por alto los objetos pequeños y de movimiento rápido.


  • bool custom_integrator

Default

false

Setter

set_use_custom_integrator(value)

Getter

is_using_custom_integrator()

Si true, la integración de la fuerza interna se desactivará (como la gravedad o la fricción del aire) para este cuerpo. Aparte de la respuesta a la colisión, el cuerpo sólo se moverá según lo determinado por la función _integrate_forces, si está definida.


Setter

set_friction(value)

Getter

get_friction()

The body's friction, from 0 (frictionless) to 1 (max friction).

Deprecated, use PhysicsMaterial.friction instead via physics_material_override.


Default

1.0

Setter

set_gravity_scale(value)

Getter

get_gravity_scale()

This is multiplied by the global 3D gravity setting found in Project > Project Settings > Physics > 3d to produce RigidBody's gravity. For example, a value of 1 will be normal gravity, 2 will apply double gravity, and 0.5 will apply half gravity to this object.


Default

-1.0

Setter

set_linear_damp(value)

Getter

get_linear_damp()

The body's linear damp. Cannot be less than -1.0. If this value is different from -1.0, any linear damp derived from the world or areas will be overridden.

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


Default

Vector3( 0, 0, 0 )

Setter

set_linear_velocity(value)

Getter

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


Default

1.0

Setter

set_mass(value)

Getter

get_mass()

La masa del cuerpo.


Default

0

Setter

set_mode(value)

Getter

get_mode()

El modo corporal. Consulte Mode para conocer los posibles valores.


Setter

set_physics_material_override(value)

Getter

get_physics_material_override()

El material de la física se sobreescribe para el cuerpo.

Si se asigna un material a esta propiedad, se utilizará en lugar de cualquier otro material de física, como por ejemplo uno heredado.


Default

false

Setter

set_sleeping(value)

Getter

is_sleeping()

Si true, el cuerpo no se moverá y no calculará fuerzas hasta que sea despertado por otro cuerpo a través de, por ejemplo, una colisión, o utilizando los métodos apply_impulse o add_force.


Default

9.8

Setter

set_weight(value)

Getter

get_weight()

El peso del cuerpo basado en su masa y la gravedad 3D global. Los valores globales se establecen en Proyecto > Configuración del proyecto > Física > 3d.

Descripciones de Métodos

Llamado durante el procesamiento de la física, que permite leer y modificar con seguridad el estado de simulación del objeto. Por defecto, funciona además del comportamiento físico habitual, pero la propiedad custom_integrator te permite deshabilitar el comportamiento por defecto y hacer una integración de fuerza totalmente personalizada para un cuerpo.


  • void add_central_force ( Vector3 force )

Añade una fuerza direccional constante (es decir, aceleración) sin afectar a la rotación.

Esto equivale a add_force(force, Vector3(0,0,0)).


Añade una fuerza direccional constante (es decir, aceleración) sin afectar a la rotación.

Esto equivale a add_force(force, Vector3(0,0,0)).


  • void add_torque ( Vector3 torque )

Añade una fuerza de rotación constante (es decir, un motor) sin afectar a la posición.


  • void apply_central_impulse ( Vector3 impulse )

Aplica un impulso direccional sin afectar a la rotación.

Esto equivale a apply_impulse(Vector3(0,0,0), impulse).


Aplica un impulso posicionado al cuerpo. ¡Un impulso es independiente del tiempo! Aplicar un impulso en cada cuadro resultaría en una fuerza dependiente del cuadro. Por esta razón, sólo debe utilizarse cuando se simulan impactos únicos. La posición utiliza la rotación del sistema de coordenadas globales, pero está centrada en el origen del objeto.


  • void apply_torque_impulse ( Vector3 impulse )

Aplica un impulso de torsión que se verá afectado por la masa y la forma del cuerpo. Esto hará girar el cuerpo alrededor del vector de impulse pasado.


Devuelve true si el eje lineal o rotativo especificado está bloqueado.


  • Array get_colliding_bodies ( ) const

Retorna una lista de los cuerpos que colisionan con éste. Requiere que contact_monitor sea true, y que contacts_reported sea lo suficientemente alto para detectar todas las colisiones.

Nota: El resultado de esta prueba no es inmediato después de mover los objetos. Para un mejor rendimiento, la lista de superposiciones se actualiza una vez por cuadro y antes del paso de física. Considere la posibilidad de utilizar señales en su lugar.


  • Basis get_inverse_inertia_tensor ( )

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


Bloquea el eje lineal o rotacional especificado.


  • void set_axis_velocity ( Vector3 axis_velocity )

Establece una velocidad del eje. La velocidad en el eje vectorial dado se fijará como la longitud del vector dado. Esto es útil para el comportamiento de salto.