RigidBody

Inherits: PhysicsBody < CollisionObject < Spatial < Node < Object

Category: Core

Brief Description

Rigid body node.

Member Functions

void _integrate_forces ( PhysicsDirectBodyState state ) virtual
void apply_impulse ( Vector3 pos, Vector3 impulse )
float get_angular_damp ( ) const
Vector3 get_angular_velocity ( ) const
int get_axis_lock ( ) const
float get_bounce ( ) const
Array get_colliding_bodies ( ) const
float get_friction ( ) const
float get_gravity_scale ( ) const
float get_linear_damp ( ) const
Vector3 get_linear_velocity ( ) const
float get_mass ( ) const
int get_max_contacts_reported ( ) const
int get_mode ( ) const
float get_weight ( ) const
bool is_able_to_sleep ( ) const
bool is_contact_monitor_enabled ( ) const
bool is_sleeping ( ) const
bool is_using_continuous_collision_detection ( ) const
bool is_using_custom_integrator ( )
void set_angular_damp ( float angular_damp )
void set_angular_velocity ( Vector3 angular_velocity )
void set_axis_lock ( int axis_lock )
void set_axis_velocity ( Vector3 axis_velocity )
void set_bounce ( float bounce )
void set_can_sleep ( bool able_to_sleep )
void set_contact_monitor ( bool enabled )
void set_friction ( float friction )
void set_gravity_scale ( float gravity_scale )
void set_linear_damp ( float linear_damp )
void set_linear_velocity ( Vector3 linear_velocity )
void set_mass ( float mass )
void set_max_contacts_reported ( int amount )
void set_mode ( int mode )
void set_sleeping ( bool sleeping )
void set_use_continuous_collision_detection ( bool enable )
void set_use_custom_integrator ( bool enable )
void set_weight ( float weight )

Signals

Emitted when a body enters into contact with this one. Contact monitor and contacts reported must be enabled for this to work.

  • body_enter_shape ( int body_id, Object body, int body_shape, int local_shape )

Emitted when a body enters into contact with this one. Contact monitor and contacts reported must be enabled for this to work.

This signal not only receives the body that collided with this one, but also its RID (body_id), the shape index from the colliding body (body_shape), and the shape index from this body (local_shape) the other body collided with.

Emitted when a body shape exits contact with this one. Contact monitor and contacts reported must be enabled for this to work.

  • body_exit_shape ( int body_id, Object body, int body_shape, int local_shape )

Emitted when a body shape exits contact with this one. Contact monitor and contacts reported must be enabled for this to work.

This signal not only receives the body that stopped colliding with this one, but also its RID (body_id), the shape index from the colliding body (body_shape), and the shape index from this body (local_shape) the other body stopped colliding with.

  • sleeping_state_changed ( )

Emitted when the body changes its sleeping state. Either by sleeping or waking up.

Numeric Constants

  • MODE_STATIC = 1 — Static mode. The body behaves like a StaticBody, and can only move by user code.
  • MODE_KINEMATIC = 3 — Kinematic body. The body behaves like a KinematicBody, and can only move by user code.
  • MODE_RIGID = 0 — Rigid body. This is the “natural” state of a rigid body. It is affected by forces, and can move, rotate, and be affected by user code.
  • MODE_CHARACTER = 2 — Character body. This behaves like a rigid body, but can not rotate.

Description

Rigid body node. This node is used for placing rigid bodies in the scene. It can contain a number of shapes, and also shift mode between regular Rigid body, Kinematic, Character or Static.

Member Function Description

Called during physics processing, allowing you to read and safely modify the simulation state for the object. By default it works in addition to the usual physics behavior, but set_use_custom_integrator allows you to disable the default behavior and do fully custom force integration for a body.

Apply a positioned impulse (which will be affected by the body mass and shape). This is the equivalent of hitting a billiard ball with a cue: a force that is applied once, and only once. Both the impulse and the offset from the body origin are in global coordinates.

  • float get_angular_damp ( ) const

Return the current body angular damp. Default is -1.

  • Vector3 get_angular_velocity ( ) const

Return the current body angular velocity.

  • int get_axis_lock ( ) const

Return the current axis lock of the body. One of AXIS_LOCK_* enum.

  • float get_bounce ( ) const

Return the current body bounciness.

  • Array get_colliding_bodies ( ) const

Return a list of the bodies colliding with this one. By default, number of max contacts reported is at 0 , see set_max_contacts_reported to increase it.

  • float get_friction ( ) const

Return the current body friction, from 0 (frictionless) to 1 (max friction).

  • float get_gravity_scale ( ) const

Return the current body gravity scale.

  • float get_linear_damp ( ) const

Return the current body linear damp. Default is -1.

  • Vector3 get_linear_velocity ( ) const

Return the current body linear velocity.

  • float get_mass ( ) const

Return the current body mass.

  • int get_max_contacts_reported ( ) const

Return the maximum contacts that can be reported. See set_max_contacts_reported.

  • int get_mode ( ) const

Return the current body mode, see set_mode.

  • float get_weight ( ) const

Return the current body weight, given standard earth-weight (gravity 9.8).

  • bool is_able_to_sleep ( ) const

Return whether the body has the ability to fall asleep when not moving. See set_can_sleep.

  • bool is_contact_monitor_enabled ( ) const

Return whether contact monitoring is enabled.

  • bool is_sleeping ( ) const

Return whether the body is sleeping.

  • bool is_using_continuous_collision_detection ( ) const

Return whether this body is using continuous collision detection.

  • bool is_using_custom_integrator ( )

Return whether the body is using a custom integrator.

  • void set_angular_damp ( float angular_damp )

Set the angular damp for this body. Default of -1, cannot be less than -1. If this value is different from -1, any angular damp derived from the world or areas will be overridden.

  • void set_angular_velocity ( Vector3 angular_velocity )

Set the body angular velocity. Can be used sporadically, but DON’T SET THIS IN EVERY FRAME, because physics may be running in another thread and definitely runs at a different granularity. Use _integrate_forces as your process loop if you want to have precise control of the body state.

  • void set_axis_lock ( int axis_lock )

Set the axis lock of the body, from the AXIS_LOCK_* enum. Axis lock stops the body from moving along the specified axis(X/Y/Z) and rotating along the other two axes.

  • void set_axis_velocity ( Vector3 axis_velocity )

Set 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_bounce ( float bounce )

Set the body bounciness, from 0 (no bounciness) to 1 (max bounciness).

  • void set_can_sleep ( bool able_to_sleep )

Set the body ability to fall asleep when not moving. This saves an enormous amount of processor time when there are plenty of rigid bodies (non static) in a scene.

Sleeping bodies are not affected by forces until a collision or an apply_impulse / set_applied_force wakes them up. Until then, they behave like a static body.

  • void set_contact_monitor ( bool enabled )

Enable contact monitoring. This allows the body to emit signals when it collides with another.

  • void set_friction ( float friction )

Set the body friction, from 0 (frictionless) to 1 (max friction).

  • void set_gravity_scale ( float gravity_scale )

Set the gravity factor. This factor multiplies gravity intensity just for this body.

  • void set_linear_damp ( float linear_damp )

Set the linear damp for this body. Default of -1, cannot be less than -1. If this value is different from -1, any linear damp derived from the world or areas will be overridden.

  • void set_linear_velocity ( Vector3 linear_velocity )

Set the body linear velocity. Can be used sporadically, but DON’T SET THIS IN EVERY FRAME, because physics may be running in another thread and definitely runs at a different granularity. Use _integrate_forces as your process loop if you want to have precise control of the body state.

  • void set_mass ( float mass )

Set the body mass.

  • void set_max_contacts_reported ( int amount )

Set the maximum contacts to report. Bodies can keep a log of the contacts with other bodies, this is enabled by setting the maximum amount of contacts reported to a number greater than 0.

  • void set_mode ( int mode )

Set the body mode, from the MODE_* enum. This allows to change to a static body or a character body.

  • void set_sleeping ( bool sleeping )

Set whether a body is sleeping or not. Sleeping bodies are not affected by forces until a collision or an apply_impulse wakes them up. Until then, they behave like a static body.

  • void set_use_continuous_collision_detection ( bool enable )

Set the continuous collision detection mode from the enum CCD_MODE_*.

Continuous collision detection tries to predict where a moving body will collide, instead of moving it and correcting its movement if it collided. The first is more precise, and misses less impacts by small, fast-moving objects. The second is faster to compute, but can miss small, fast-moving objects.

  • void set_use_custom_integrator ( bool enable )

Pass true to disable the internal force integration (like gravity or air friction) for this body. Other than collision response, the body will only move as determined by the _integrate_forces function, if defined.

  • void set_weight ( float weight )

Set the body weight given standard earth-weight (gravity 9.8).