pub struct RigidBody {
pub user_data: u128,
/* private fields */
}Expand description
A physical object that can move, rotate, and collide with other objects in your simulation.
Rigid bodies are the fundamental moving objects in physics simulations. Think of them as the “physical representation” of your game objects - a character, a crate, a vehicle, etc.
§Body types
- Dynamic: Affected by forces, gravity, and collisions. Use for objects that should move realistically (falling boxes, projectiles, etc.)
- Fixed: Never moves. Use for static geometry like walls, floors, and terrain
- Kinematic: Moved by setting velocity or position directly, not by forces. Use for moving platforms, doors, or player-controlled characters
§Creating bodies
Always use RigidBodyBuilder to create new rigid bodies:
let body = RigidBodyBuilder::dynamic()
.translation(vector![0.0, 10.0, 0.0])
.build();
let handle = bodies.insert(body);Fields§
§user_data: u128User-defined data associated to this rigid-body.
Implementations§
Source§impl RigidBody
impl RigidBody
Sourcepub fn copy_from(&mut self, other: &RigidBody)
pub fn copy_from(&mut self, other: &RigidBody)
Copy all the characteristics from other to self.
If you have a mutable reference to a rigid-body rigid_body: &mut RigidBody, attempting to
assign it a whole new rigid-body instance, e.g., *rigid_body = RigidBodyBuilder::dynamic().build(),
will crash due to some internal indices being overwritten. Instead, use
rigid_body.copy_from(&RigidBodyBuilder::dynamic().build()).
This method will allow you to set most characteristics of this rigid-body from another rigid-body instance without causing any breakage.
This method cannot be used for editing the list of colliders attached to this rigid-body.
Therefore, the list of colliders attached to self won’t be replaced by the one attached
to other.
The pose of other will only copied into self if self doesn’t have a parent (if it has
a parent, its position is directly controlled by the parent rigid-body).
Sourcepub fn additional_solver_iterations(&self) -> usize
pub fn additional_solver_iterations(&self) -> usize
Set the additional number of solver iterations run for this rigid-body and everything interacting with it.
See Self::set_additional_solver_iterations for additional information.
Sourcepub fn set_additional_solver_iterations(&mut self, additional_iterations: usize)
pub fn set_additional_solver_iterations(&mut self, additional_iterations: usize)
Set the additional number of solver iterations run for this rigid-body and everything interacting with it.
Increasing this number will help improve simulation accuracy on this rigid-body and every rigid-body interacting directly or indirectly with it (through joints or contacts). This implies a performance hit.
The default value is 0, meaning exactly IntegrationParameters::num_solver_iterations will
be used as number of solver iterations for this body.
Sourcepub fn activation(&self) -> &RigidBodyActivation
pub fn activation(&self) -> &RigidBodyActivation
The activation status of this rigid-body.
Sourcepub fn activation_mut(&mut self) -> &mut RigidBodyActivation
pub fn activation_mut(&mut self) -> &mut RigidBodyActivation
Mutable reference to the activation status of this rigid-body.
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Is this rigid-body enabled?
Sourcepub fn set_enabled(&mut self, enabled: bool)
pub fn set_enabled(&mut self, enabled: bool)
Sets whether this rigid-body is enabled or not.
Sourcepub fn linear_damping(&self) -> f32
pub fn linear_damping(&self) -> f32
The linear damping coefficient (velocity reduction over time).
Damping gradually slows down moving objects. 0.0 = no damping (infinite momentum),
higher values = faster slowdown. Use for air resistance, friction, etc.
Sourcepub fn set_linear_damping(&mut self, damping: f32)
pub fn set_linear_damping(&mut self, damping: f32)
Sets how quickly linear velocity decreases over time.
0.0= no slowdown (space/frictionless)0.1= gradual slowdown (air resistance)1.0+= rapid slowdown (thick fluid)
Sourcepub fn angular_damping(&self) -> f32
pub fn angular_damping(&self) -> f32
The angular damping coefficient (rotation slowdown over time).
Like linear damping but for rotation. Higher values make spinning objects stop faster.
Sourcepub fn set_angular_damping(&mut self, damping: f32)
pub fn set_angular_damping(&mut self, damping: f32)
Sets how quickly angular velocity decreases over time.
Controls how fast spinning objects slow down.
Sourcepub fn body_type(&self) -> RigidBodyType
pub fn body_type(&self) -> RigidBodyType
The type of this rigid-body.
Sourcepub fn set_body_type(&mut self, status: RigidBodyType, wake_up: bool)
pub fn set_body_type(&mut self, status: RigidBodyType, wake_up: bool)
Sets the type of this rigid-body.
Sourcepub fn center_of_mass(&self) -> &Point<f32>
pub fn center_of_mass(&self) -> &Point<f32>
The center of mass position in world coordinates.
This is the “balance point” where the body’s mass is centered. Forces applied here produce no rotation, only translation.
Sourcepub fn local_center_of_mass(&self) -> &Point<f32>
pub fn local_center_of_mass(&self) -> &Point<f32>
The center of mass in the body’s local coordinate system.
This is relative to the body’s position, computed from attached colliders.
Sourcepub fn mass_properties(&self) -> &RigidBodyMassProps
pub fn mass_properties(&self) -> &RigidBodyMassProps
The mass-properties of this rigid-body.
Sourcepub fn effective_dominance_group(&self) -> i16
pub fn effective_dominance_group(&self) -> i16
The dominance group of this rigid-body.
This method always returns i8::MAX + 1 for non-dynamic
rigid-bodies.
Sourcepub fn set_locked_axes(&mut self, locked_axes: LockedAxes, wake_up: bool)
pub fn set_locked_axes(&mut self, locked_axes: LockedAxes, wake_up: bool)
Sets the axes along which this rigid-body cannot translate or rotate.
Sourcepub fn locked_axes(&self) -> LockedAxes
pub fn locked_axes(&self) -> LockedAxes
The axes along which this rigid-body cannot translate or rotate.
Sourcepub fn lock_rotations(&mut self, locked: bool, wake_up: bool)
pub fn lock_rotations(&mut self, locked: bool, wake_up: bool)
Locks or unlocks all rotational movement for this body.
When locked, the body cannot rotate at all (useful for keeping objects upright). Use for characters that shouldn’t tip over, or objects that should only slide.
Sourcepub fn set_enabled_rotations(
&mut self,
allow_rotations_x: bool,
allow_rotations_y: bool,
allow_rotations_z: bool,
wake_up: bool,
)
pub fn set_enabled_rotations( &mut self, allow_rotations_x: bool, allow_rotations_y: bool, allow_rotations_z: bool, wake_up: bool, )
Locks or unlocks rotations of this rigid-body along each cartesian axes.
Sourcepub fn restrict_rotations(
&mut self,
allow_rotations_x: bool,
allow_rotations_y: bool,
allow_rotations_z: bool,
wake_up: bool,
)
👎Deprecated: Use set_enabled_rotations instead
pub fn restrict_rotations( &mut self, allow_rotations_x: bool, allow_rotations_y: bool, allow_rotations_z: bool, wake_up: bool, )
set_enabled_rotations insteadLocks or unlocks rotations of this rigid-body along each cartesian axes.
Sourcepub fn lock_translations(&mut self, locked: bool, wake_up: bool)
pub fn lock_translations(&mut self, locked: bool, wake_up: bool)
Locks or unlocks all translational movement for this body.
When locked, the body cannot move from its position (but can still rotate). Use for rotating platforms, turrets, or objects fixed in space.
Sourcepub fn set_enabled_translations(
&mut self,
allow_translation_x: bool,
allow_translation_y: bool,
allow_translation_z: bool,
wake_up: bool,
)
pub fn set_enabled_translations( &mut self, allow_translation_x: bool, allow_translation_y: bool, allow_translation_z: bool, wake_up: bool, )
Locks or unlocks rotations of this rigid-body along each cartesian axes.
Sourcepub fn restrict_translations(
&mut self,
allow_translation_x: bool,
allow_translation_y: bool,
allow_translation_z: bool,
wake_up: bool,
)
👎Deprecated: Use set_enabled_translations instead
pub fn restrict_translations( &mut self, allow_translation_x: bool, allow_translation_y: bool, allow_translation_z: bool, wake_up: bool, )
set_enabled_translations insteadLocks or unlocks rotations of this rigid-body along each cartesian axes.
Sourcepub fn is_translation_locked(&self) -> bool
pub fn is_translation_locked(&self) -> bool
Are the translations of this rigid-body locked?
Sourcepub fn is_rotation_locked(&self) -> [bool; 3]
pub fn is_rotation_locked(&self) -> [bool; 3]
Returns true for each rotational degrees of freedom locked on this rigid-body.
Sourcepub fn enable_ccd(&mut self, enabled: bool)
pub fn enable_ccd(&mut self, enabled: bool)
Enables or disables Continuous Collision Detection for this body.
CCD prevents fast-moving objects from tunneling through thin walls, but costs more CPU. Enable for bullets, fast projectiles, or any object that must never pass through geometry.
Sourcepub fn is_ccd_enabled(&self) -> bool
pub fn is_ccd_enabled(&self) -> bool
Checks if CCD is enabled for this body.
Returns true if CCD is turned on (not whether it’s currently active this frame).
Sourcepub fn set_soft_ccd_prediction(&mut self, prediction_distance: f32)
pub fn set_soft_ccd_prediction(&mut self, prediction_distance: f32)
Sets the maximum prediction distance Soft Continuous Collision-Detection.
When set to 0, soft-CCD is disabled. Soft-CCD helps prevent tunneling especially of slow-but-thin to moderately fast objects. The soft CCD prediction distance indicates how far in the object’s path the CCD algorithm is allowed to inspect. Large values can impact performance badly by increasing the work needed from the broad-phase.
It is a generally cheaper variant of regular CCD (that can be enabled with
RigidBody::enable_ccd since it relies on predictive constraints instead of
shape-cast and substeps.
Sourcepub fn soft_ccd_prediction(&self) -> f32
pub fn soft_ccd_prediction(&self) -> f32
The soft-CCD prediction distance for this rigid-body.
See the documentation of RigidBody::set_soft_ccd_prediction for additional details on
soft-CCD.
Sourcepub fn is_ccd_active(&self) -> bool
pub fn is_ccd_active(&self) -> bool
Is CCD active for this rigid-body?
The CCD is considered active if the rigid-body is moving at a velocity greater than an automatically-computed threshold.
This is not the same as self.is_ccd_enabled which only
checks if CCD is enabled to run for this rigid-body or if
it is completely disabled (independently from its velocity).
Sourcepub fn recompute_mass_properties_from_colliders(
&mut self,
colliders: &ColliderSet,
)
pub fn recompute_mass_properties_from_colliders( &mut self, colliders: &ColliderSet, )
Recalculates mass, center of mass, and inertia from attached colliders.
Normally automatic, but call this if you modify collider shapes/masses at runtime. Only needed after directly modifying colliders without going through the builder.
Sourcepub fn set_additional_mass(&mut self, additional_mass: f32, wake_up: bool)
pub fn set_additional_mass(&mut self, additional_mass: f32, wake_up: bool)
Adds extra mass on top of collider-computed mass.
Total mass = collider masses + this additional mass. Use when you want to make a body heavier without changing collider densities.
§Example
// Add 50kg to make this body heavier
bodies[body].set_additional_mass(50.0, true);Angular inertia is automatically scaled to match the mass increase.
Updated automatically at next physics step or call recompute_mass_properties_from_colliders().
Sourcepub fn set_additional_mass_properties(
&mut self,
props: MassProperties,
wake_up: bool,
)
pub fn set_additional_mass_properties( &mut self, props: MassProperties, wake_up: bool, )
Sets the rigid-body’s additional mass-properties.
This is only the “additional” mass-properties because the total mass-properties of the rigid-body is equal to the sum of this additional mass-properties and the mass computed from the colliders (with non-zero densities) attached to this rigid-body.
That total mass-properties (which include the attached colliders’ contributions)
will be updated at the name physics step, or can be updated manually with
Self::recompute_mass_properties_from_colliders.
This will override any previous mass-properties set by Self::set_additional_mass,
Self::set_additional_mass_properties, RigidBodyBuilder::additional_mass, or
RigidBodyBuilder::additional_mass_properties for this rigid-body.
If wake_up is true then the rigid-body will be woken up if it was
put to sleep because it did not move for a while.
Sourcepub fn colliders(&self) -> &[ColliderHandle]
pub fn colliders(&self) -> &[ColliderHandle]
Returns handles of all colliders attached to this body.
Use to iterate over a body’s collision shapes or to modify them.
§Example
for collider_handle in bodies[body].colliders() {
if let Some(collider) = colliders.get_mut(*collider_handle) {
collider.set_friction(0.5);
}
}Sourcepub fn is_dynamic(&self) -> bool
pub fn is_dynamic(&self) -> bool
Checks if this is a dynamic body (moves via forces and collisions).
Dynamic bodies are fully simulated and respond to gravity, forces, and collisions.
Sourcepub fn is_kinematic(&self) -> bool
pub fn is_kinematic(&self) -> bool
Checks if this is a kinematic body (moves via direct velocity/position control).
Kinematic bodies move by setting velocity directly, not by applying forces.
Sourcepub fn is_dynamic_or_kinematic(&self) -> bool
pub fn is_dynamic_or_kinematic(&self) -> bool
Is this rigid-body a dynamic rigid-body or a kinematic rigid-body?
This method is mostly convenient internally where kinematic and dynamic rigid-body are subject to the same behavior.
Sourcepub fn effective_active_set_offset(&self) -> u32
pub fn effective_active_set_offset(&self) -> u32
The offset index in the solver’s active set, or u32::MAX if
the rigid-body isn’t dynamic or kinematic.
Sourcepub fn is_fixed(&self) -> bool
pub fn is_fixed(&self) -> bool
Checks if this is a fixed body (never moves, infinite mass).
Fixed bodies are static geometry: walls, floors, terrain. They never move and are not affected by any forces or collisions.
Sourcepub fn mass(&self) -> f32
pub fn mass(&self) -> f32
The mass of this rigid body in kilograms.
Returns zero for fixed bodies (which technically have infinite mass). Mass is computed from attached colliders’ shapes and densities.
Sourcepub fn next_position(&self) -> &Isometry<f32>
pub fn next_position(&self) -> &Isometry<f32>
The predicted position of this rigid-body.
If this rigid-body is kinematic this value is set by the set_next_kinematic_position
method and is used for estimating the kinematic body velocity at the next timestep.
For non-kinematic bodies, this value is currently unspecified.
Sourcepub fn gravity_scale(&self) -> f32
pub fn gravity_scale(&self) -> f32
The gravity scale multiplier for this body.
1.0(default) = normal gravity0.0= no gravity (floating)2.0= double gravity (heavy/fast falling)- Negative values = reverse gravity (objects fall upward!)
Sourcepub fn set_gravity_scale(&mut self, scale: f32, wake_up: bool)
pub fn set_gravity_scale(&mut self, scale: f32, wake_up: bool)
Sets how much gravity affects this body (multiplier).
§Examples
bodies[body].set_gravity_scale(0.0, true); // Zero-G (space)
bodies[body].set_gravity_scale(0.1, true); // Moon gravity
bodies[body].set_gravity_scale(2.0, true); // Extra heavySourcepub fn dominance_group(&self) -> i8
pub fn dominance_group(&self) -> i8
The dominance group of this rigid-body.
Sourcepub fn set_dominance_group(&mut self, dominance: i8)
pub fn set_dominance_group(&mut self, dominance: i8)
The dominance group of this rigid-body.
Sourcepub fn sleep(&mut self)
pub fn sleep(&mut self)
Forces this body to sleep immediately (stop simulating it).
Sleeping bodies are excluded from physics simulation until disturbed. Use to manually deactivate bodies you know won’t move for a while.
The body will auto-wake if:
- Hit by a moving object
- Connected via joint to a moving body
- Manually woken with
wake_up()
Sourcepub fn wake_up(&mut self, strong: bool)
pub fn wake_up(&mut self, strong: bool)
Wakes up this body if it’s sleeping, making it active in the simulation.
§Parameters
strong- Iftrue, guarantees the body stays awake for multiple frames. Iffalse, it might sleep again immediately if conditions are met.
Use after manually moving a sleeping body or to keep it active temporarily.
Sourcepub fn is_sleeping(&self) -> bool
pub fn is_sleeping(&self) -> bool
Is this rigid body sleeping?
Sourcepub fn is_moving(&self) -> bool
pub fn is_moving(&self) -> bool
Returns true if the body has non-zero linear or angular velocity.
Useful for checking if an object is actually moving vs sitting still.
Sourcepub fn vels(&self) -> &RigidBodyVelocity<f32>
pub fn vels(&self) -> &RigidBodyVelocity<f32>
Returns both linear and angular velocity as a combined structure.
Most users should use linvel() and angvel() separately instead.
Sourcepub fn linvel(&self) -> &Vector<f32>
pub fn linvel(&self) -> &Vector<f32>
The current linear velocity (speed and direction of movement).
This is how fast the body is moving in units per second. Use with set_linvel()
to directly control the body’s movement speed.
Sourcepub fn angvel(&self) -> &Vector<f32>
pub fn angvel(&self) -> &Vector<f32>
The current angular velocity (rotation speed) in 3D.
Returns a vector in radians per second around each axis (X, Y, Z).
Sourcepub fn set_vels(&mut self, vels: RigidBodyVelocity<f32>, wake_up: bool)
pub fn set_vels(&mut self, vels: RigidBodyVelocity<f32>, wake_up: bool)
Set both the angular and linear velocity of this rigid-body.
If wake_up is true then the rigid-body will be woken up if it was
put to sleep because it did not move for a while.
Sourcepub fn set_linvel(&mut self, linvel: Vector<f32>, wake_up: bool)
pub fn set_linvel(&mut self, linvel: Vector<f32>, wake_up: bool)
Sets how fast this body is moving (linear velocity).
This directly sets the body’s velocity without applying forces. Use for:
- Player character movement
- Kinematic object control
- Instantly changing an object’s speed
For physics-based movement, consider using apply_impulse() or
add_force() instead for more realistic behavior.
§Example
// Make the body move to the right at 5 units/second
bodies[body].set_linvel(vector![5.0, 0.0, 0.0], true);Sourcepub fn set_angvel(&mut self, angvel: Vector<f32>, wake_up: bool)
pub fn set_angvel(&mut self, angvel: Vector<f32>, wake_up: bool)
The angular velocity of this rigid-body.
If wake_up is true then the rigid-body will be woken up if it was
put to sleep because it did not move for a while.
Sourcepub fn position(&self) -> &Isometry<f32>
pub fn position(&self) -> &Isometry<f32>
The current position (translation + rotation) of this rigid body in world space.
Returns an Isometry which combines both translation and rotation.
For just the position vector, use translation() instead.
Sourcepub fn translation(&self) -> &Vector<f32>
pub fn translation(&self) -> &Vector<f32>
The current position vector of this rigid body (world coordinates).
This is just the XYZ location, without rotation. For the full pose (position + rotation),
use position().
Sourcepub fn set_translation(&mut self, translation: Vector<f32>, wake_up: bool)
pub fn set_translation(&mut self, translation: Vector<f32>, wake_up: bool)
Teleports this rigid body to a new position (world coordinates).
⚠️ Warning: This instantly moves the body, ignoring physics! The body will “teleport” without checking for collisions in between. Use this for:
- Respawning objects
- Level transitions
- Resetting positions
For smooth physics-based movement, use velocities or forces instead.
§Parameters
wake_up- Iftrue, prevents the body from immediately going back to sleep
Sourcepub fn set_rotation(&mut self, rotation: Rotation<f32>, wake_up: bool)
pub fn set_rotation(&mut self, rotation: Rotation<f32>, wake_up: bool)
Instantly rotates this rigid body to a new orientation.
⚠️ Warning: This teleports the rotation, ignoring physics! See set_translation() for details.
Sourcepub fn set_position(&mut self, pos: Isometry<f32>, wake_up: bool)
pub fn set_position(&mut self, pos: Isometry<f32>, wake_up: bool)
Teleports this body to a new position and rotation (ignoring physics).
⚠️ Warning: Instantly moves the body without checking for collisions! For position-based kinematic bodies, this also resets their interpolated velocity to zero.
Use for respawning, level transitions, or resetting positions.
Sourcepub fn set_next_kinematic_rotation(&mut self, rotation: Rotation<f32>)
pub fn set_next_kinematic_rotation(&mut self, rotation: Rotation<f32>)
For position-based kinematic bodies: sets where the body should rotate to by next frame.
Only works for KinematicPositionBased bodies. Rapier computes the angular velocity
needed to reach this rotation smoothly.
Sourcepub fn set_next_kinematic_translation(&mut self, translation: Vector<f32>)
pub fn set_next_kinematic_translation(&mut self, translation: Vector<f32>)
For position-based kinematic bodies: sets where the body should move to by next frame.
Only works for KinematicPositionBased bodies. Rapier computes the velocity
needed to reach this position smoothly.
Sourcepub fn set_next_kinematic_position(&mut self, pos: Isometry<f32>)
pub fn set_next_kinematic_position(&mut self, pos: Isometry<f32>)
For position-based kinematic bodies: sets the target pose (position + rotation) for next frame.
Only works for KinematicPositionBased bodies. Combines translation and rotation control.
Sourcepub fn predict_position_using_velocity_and_forces(
&self,
dt: f32,
) -> Isometry<f32>
pub fn predict_position_using_velocity_and_forces( &self, dt: f32, ) -> Isometry<f32>
Calculates where this body will be after dt seconds, considering current velocity AND forces.
Useful for predicting future positions or implementing custom integration. Accounts for gravity and applied forces.
Sourcepub fn predict_position_using_velocity(&self, dt: f32) -> Isometry<f32>
pub fn predict_position_using_velocity(&self, dt: f32) -> Isometry<f32>
Calculates where this body will be after dt seconds, considering only current velocity (not forces).
Like predict_position_using_velocity_and_forces() but ignores applied forces.
Useful when you only care about inertial motion without acceleration.
Source§impl RigidBody
§Applying forces and torques
impl RigidBody
§Applying forces and torques
Sourcepub fn reset_forces(&mut self, wake_up: bool)
pub fn reset_forces(&mut self, wake_up: bool)
Clears all forces that were added with add_force().
Forces are automatically cleared each physics step, so you rarely need this. Useful if you want to cancel forces mid-frame.
Sourcepub fn reset_torques(&mut self, wake_up: bool)
pub fn reset_torques(&mut self, wake_up: bool)
Clears all torques that were added with add_torque().
Torques are automatically cleared each physics step. Rarely needed.
Sourcepub fn add_force(&mut self, force: Vector<f32>, wake_up: bool)
pub fn add_force(&mut self, force: Vector<f32>, wake_up: bool)
Applies a continuous force to this body (like thrust, wind, or magnets).
Unlike apply_impulse() which is instant, forces are applied
continuously over time and accumulate until the next physics step. Use for:
- Rocket/jet thrust
- Wind or water currents
- Magnetic/gravity fields
- Continuous pushing/pulling
Forces are automatically cleared after each physics step, so you typically call this every frame if you want continuous force application.
§Example
// Apply thrust every frame
bodies[body].add_force(vector![0.0, 100.0, 0.0], true);Only affects dynamic bodies (does nothing for kinematic/fixed bodies).
Sourcepub fn add_torque(&mut self, torque: Vector<f32>, wake_up: bool)
pub fn add_torque(&mut self, torque: Vector<f32>, wake_up: bool)
Applies a continuous rotational force (torque) to spin this body.
Like add_force() but for rotation. In 3D, the torque vector direction
determines the rotation axis (right-hand rule).
Only affects dynamic bodies.
Sourcepub fn add_force_at_point(
&mut self,
force: Vector<f32>,
point: Point<f32>,
wake_up: bool,
)
pub fn add_force_at_point( &mut self, force: Vector<f32>, point: Point<f32>, wake_up: bool, )
Applies force at a specific point on the body (creates both force and torque).
When you push an object off-center, it both moves AND spins. This method handles both effects. The force creates linear acceleration, and the offset from center-of-mass creates torque.
Use for: Forces applied at contact points, explosions at specific locations, pushing objects.
§Parameters
force- The force vector to applypoint- Where to apply the force (world coordinates)
Only affects dynamic bodies.
Source§impl RigidBody
§Applying impulses and angular impulses
impl RigidBody
§Applying impulses and angular impulses
Sourcepub fn apply_impulse(&mut self, impulse: Vector<f32>, wake_up: bool)
pub fn apply_impulse(&mut self, impulse: Vector<f32>, wake_up: bool)
Instantly changes the velocity by applying an impulse (like a kick or explosion).
An impulse is an instant change in momentum. Think of it as a “one-time push” that immediately affects velocity. Use for:
- Jumping (apply upward impulse)
- Explosions pushing objects away
- Getting hit by something
- Launching projectiles
The effect depends on the body’s mass - heavier objects will be affected less by the same impulse.
For continuous forces (like rocket thrust or wind), use add_force() instead.
§Example
// Make a character jump
bodies[body].apply_impulse(vector![0.0, 300.0, 0.0], true);Only affects dynamic bodies (does nothing for kinematic/fixed bodies).
Sourcepub fn apply_torque_impulse(
&mut self,
torque_impulse: Vector<f32>,
wake_up: bool,
)
pub fn apply_torque_impulse( &mut self, torque_impulse: Vector<f32>, wake_up: bool, )
Instantly changes rotation speed by applying angular impulse (like a sudden spin).
In 3D, the impulse vector direction determines the spin axis (right-hand rule).
Like apply_impulse() but for rotation. Only affects dynamic bodies.
Sourcepub fn apply_impulse_at_point(
&mut self,
impulse: Vector<f32>,
point: Point<f32>,
wake_up: bool,
)
pub fn apply_impulse_at_point( &mut self, impulse: Vector<f32>, point: Point<f32>, wake_up: bool, )
Applies impulse at a specific point on the body (creates both linear and angular effects).
Like add_force_at_point() but instant instead of continuous. When you hit an object
off-center, it both flies away AND spins - this method handles both.
§Example
// Hit the top-left corner of a box
bodies[body].apply_impulse_at_point(
vector![100.0, 0.0, 0.0],
point![-0.5, 0.5, 0.0], // Top-left of a 1x1 box
true
);
// Box will move right AND spinOnly affects dynamic bodies.
Sourcepub fn user_force(&self) -> Vector<f32>
pub fn user_force(&self) -> Vector<f32>
Returns the total force currently queued to be applied this frame.
This is the sum of all add_force() calls since the last physics step.
Returns zero for non-dynamic bodies.
Sourcepub fn user_torque(&self) -> AngVector<f32>
pub fn user_torque(&self) -> AngVector<f32>
Returns the total torque currently queued to be applied this frame.
This is the sum of all add_torque() calls since the last physics step.
Returns zero for non-dynamic bodies.
Sourcepub fn gyroscopic_forces_enabled(&self) -> bool
pub fn gyroscopic_forces_enabled(&self) -> bool
Checks if gyroscopic forces are enabled (3D only).
Gyroscopic forces cause spinning objects to resist changes in rotation axis (like how spinning tops stay upright). Adds slight CPU cost.
Sourcepub fn enable_gyroscopic_forces(&mut self, enabled: bool)
pub fn enable_gyroscopic_forces(&mut self, enabled: bool)
Enables/disables gyroscopic forces for more realistic spinning behavior.
When enabled, rapidly spinning objects resist rotation axis changes (like gyroscopes). Examples: spinning tops, flywheels, rotating spacecraft.
Default: Disabled (costs performance, rarely needed in games).
Source§impl RigidBody
impl RigidBody
Sourcepub fn velocity_at_point(&self, point: &Point<f32>) -> Vector<f32>
pub fn velocity_at_point(&self, point: &Point<f32>) -> Vector<f32>
Calculates the velocity at a specific point on this body.
Due to rotation, different points on a rigid body move at different speeds. This computes the linear velocity at any world-space point.
Useful for: impact calculations, particle effects, sound volume based on impact speed.
Sourcepub fn kinetic_energy(&self) -> f32
pub fn kinetic_energy(&self) -> f32
Calculates the kinetic energy of this body (energy from motion).
Returns 0.5 * mass * velocity² + 0.5 * inertia * angular_velocity²
Useful for physics-based gameplay (energy tracking, damage based on impact energy).
Sourcepub fn gravitational_potential_energy(
&self,
dt: f32,
gravity: Vector<f32>,
) -> f32
pub fn gravitational_potential_energy( &self, dt: f32, gravity: Vector<f32>, ) -> f32
Calculates the gravitational potential energy of this body.
Returns mass * gravity * height. Useful for energy conservation checks.
Sourcepub fn angvel_with_gyroscopic_forces(&self, dt: f32) -> AngVector<f32>
pub fn angvel_with_gyroscopic_forces(&self, dt: f32) -> AngVector<f32>
Computes the angular velocity of this rigid-body after application of gyroscopic forces.
Trait Implementations§
Source§impl From<RigidBodyBuilder> for RigidBody
impl From<RigidBodyBuilder> for RigidBody
Source§fn from(val: RigidBodyBuilder) -> RigidBody
fn from(val: RigidBodyBuilder) -> RigidBody
Source§impl HasModifiedFlag for RigidBody
impl HasModifiedFlag for RigidBody
Source§fn has_modified_flag(&self) -> bool
fn has_modified_flag(&self) -> bool
Source§fn set_modified_flag(&mut self)
fn set_modified_flag(&mut self)
Auto Trait Implementations§
impl Freeze for RigidBody
impl RefUnwindSafe for RigidBody
impl Send for RigidBody
impl Sync for RigidBody
impl Unpin for RigidBody
impl UnwindSafe for RigidBody
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.