Struct RigidBody
Physics Body whose position is determined through physics simulation in 3D space.
struct RigidBody
;
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 mode
s: 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 integrateForces
, 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 customIntegrator
.
Properties
Name | Type | Description |
---|---|---|
angularDamp [get, set]
|
double | Damps RigidBody's rotational forces. |
angularVelocity [get, set]
|
Vector3 | RigidBody's rotational velocity. |
axisLockAngularX [get, set]
|
bool | Lock the body's rotation in the X axis. |
axisLockAngularY [get, set]
|
bool | Lock the body's rotation in the Y axis. |
axisLockAngularZ [get, set]
|
bool | Lock the body's rotation in the Z axis. |
axisLockLinearX [get, set]
|
bool | Lock the body's movement in the X axis. |
axisLockLinearY [get, set]
|
bool | Lock the body's movement in the Y axis. |
axisLockLinearZ [get, set]
|
bool | Lock the body's movement in the Z axis. |
bounce [get, set]
|
double | The body's bounciness. Values range from 0 (no bounce) to 1 (full bounciness).
Deprecated, use PhysicsMaterial instead via physicsMaterialOverride .
|
canSleep [get, set]
|
bool | If true , the RigidBody will not calculate forces and will act as a static body while there is no movement. It will wake up when forces are applied through other collisions or when the apply_impulse method is used.
|
contactMonitor [get, set]
|
bool | If true , the RigidBody will emit signals when it collides with another RigidBody.
|
contactsReported [get, set]
|
long | 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. |
continuousCd [get, set]
|
bool | 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.
|
customIntegrator [get, set]
|
bool | If true , internal force integration will be disabled (like gravity or air friction) for this body. Other than collision response, the body will only move as determined by the integrateForces function, if defined.
|
friction [get, set]
|
double | The body's friction, from 0 (frictionless) to 1 (max friction).
Deprecated, use PhysicsMaterial instead via physicsMaterialOverride .
|
gravityScale [get, set]
|
double | 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. |
linearDamp [get, set]
|
double | 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. |
linearVelocity [get, set]
|
Vector3 | The body's linear velocity. 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 integrateForces as your process loop for precise control of the body state.
|
mass [get, set]
|
double | The body's mass. |
mode [get, set]
|
RigidBody | The body mode. See mode for possible values.
|
physicsMaterialOverride [get, set]
|
PhysicsMaterial | 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. |
sleeping [get, set]
|
bool | If true , the body is sleeping and will not calculate forces until woken up by a collision or the apply_impulse method.
|
weight [get, set]
|
double | The body's weight based on its mass and the global 3D gravity. Global values are set in Project > Project Settings > Physics > 3d. |
Methods
Name | Description |
---|---|
_bodyEnterTree
|
|
_bodyExitTree
|
|
_directStateChanged
|
|
_integrateForces
|
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 the customIntegrator property allows you to disable the default behavior and do fully custom force integration for a body.
|
_reloadPhysicsCharacteristics
|
|
addCentralForce
|
Adds a constant directional force without affecting rotation.
This is equivalent to add_force(force, Vector3(0,0,0)) .
|
addForce
|
Adds a constant force (i.e. acceleration). |
addTorque
|
Adds a constant rotational force (i.e. a motor) without affecting position. |
applyCentralImpulse
|
Applies a directional impulse without affecting rotation.
This is equivalent to apply_impulse(Vector3(0,0,0), impulse) .
|
applyImpulse
|
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. The position uses the rotation of the global coordinate system, but is centered at the object's origin. |
applyTorqueImpulse
|
Applies a torque impulse which will be affected by the body mass and shape. This will rotate the body around the impulse vector passed.
|
getAngularDamp
|
|
getAngularVelocity
|
|
getAxisLock
|
Returns true if the specified linear or rotational axis is locked.
|
getBounce
|
|
getCollidingBodies
|
Returns a list of the bodies colliding with this one. By default, number of max contacts reported is at 0, see the contactsReported property to increase it.
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.
|
getFriction
|
|
getGravityScale
|
|
getLinearDamp
|
|
getLinearVelocity
|
|
getMass
|
|
getMaxContactsReported
|
|
getMode
|
|
getPhysicsMaterialOverride
|
|
getWeight
|
|
isAbleToSleep
|
|
isContactMonitorEnabled
|
|
isSleeping
|
|
isUsingContinuousCollisionDetection
|
|
isUsingCustomIntegrator
|
|
setAngularDamp
|
|
setAngularVelocity
|
|
setAxisLock
|
Locks the specified linear or rotational axis. |
setAxisVelocity
|
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. |
setBounce
|
|
setCanSleep
|
|
setContactMonitor
|
|
setFriction
|
|
setGravityScale
|
|
setLinearDamp
|
|
setLinearVelocity
|
|
setMass
|
|
setMaxContactsReported
|
|
setMode
|
|
setPhysicsMaterialOverride
|
|
setSleeping
|
|
setUseContinuousCollisionDetection
|
|
setUseCustomIntegrator
|
|
setWeight
|
Enums
Name | Description |
---|---|
Constants
|
|
Mode
|