pub struct RigidBody { /* private fields */ }Expand description
Rigid body state. Waking requests activation of its contact island on the next step.
Implementations§
Source§impl RigidBody
impl RigidBody
Sourcepub fn validate_definition(
&self,
colliders: &[Collider],
) -> Result<(), BodyValidationError>
pub fn validate_definition( &self, colliders: &[Collider], ) -> Result<(), BodyValidationError>
Checks this body’s authored state against a proposed collider slice.
Checks body fields first, then the child limit and each collider in slice order, then derived mass/inertia. The first failing field is returned. Fixed/kinematic bodies permit empty or massless geometry; dynamic bodies need positive combined mass and invertible inertia. Zero-density children are valid when the combined mass is valid.
This allocation-free check does not mutate the body or colliders,
inspect attached handles, or alter cached mass. See
RigidBodyBuilder::try_build_with_colliders for an insertion example.
Source§impl RigidBody
impl RigidBody
pub fn translation(&self) -> Vec2
pub fn rotation(&self) -> &Rotation2
pub fn linvel(&self) -> Vec2
pub fn angvel(&self) -> f32
pub fn center_of_mass(&self) -> Vec2
pub fn local_center_of_mass(&self) -> Vec2
pub fn velocity_at_point(&self, p: Vec2) -> Vec2
pub fn mass(&self) -> f32
pub fn colliders(&self) -> &[ColliderHandle]
pub fn is_ccd_enabled(&self) -> bool
pub fn enable_ccd(&mut self, enabled: bool)
pub fn is_sleeping(&self) -> bool
pub fn wake_up(&mut self, _strong: bool)
Sourcepub fn try_teleport(
&mut self,
pose: RigidBodyPose,
options: TeleportOptions,
) -> Result<RigidBodyPose, TeleportError>
pub fn try_teleport( &mut self, pose: RigidBodyPose, options: TeleportOptions, ) -> Result<RigidBodyPose, TeleportError>
Atomically set the body-origin pose and apply independent reset policies.
Rejects non-finite translation, invalid rotation and exhausted contact revision before changing anything. Rotation uses the math crate’s checked normalization (zero and non-finite quaternions are rejected). Success always invalidates cached contact/joint impulses and wakes this body, including an identical-pose reset. Old/new solid contact and enabled-joint islands wake on the next valid world step, using existing revision flags. Sensors do not connect wake islands. No simulation tick is executed here.
Identity, children, joint anchors/configuration, mass, CCD, gravity scale
and damping are retained. Preserve retains stored world-space COM and
angular velocities, not origin-point velocity or angular momentum. A
kinematic body’s next step still derives its velocities from any retained
targets (or zero with no targets). Retained targets can move it away from
the new pose on that step; clearing targets prevents this snap back.
Forces/torque retained by policy apply on the next step as usual.
The returned committed pose lets hosts snap both interpolation samples. Last-step contacts/manifolds/events remain snapshots until the next valid step; their impulses cannot be reused after this revision change. This operation performs no destination search or overlap rejection and allocates no storage. Existing joints may correct the pose or break on a later step.
use ferravex_math::Vec2;
use ferravex_physics::{Rotation2, d2::{
ColliderBuilder, PhysicsWorld, RigidBodyBuilder, RigidBodyPose,
TeleportOptions, VelocityPolicy,
}};
let mut world = PhysicsWorld::default();
let (ball, child) = world.insert(
RigidBodyBuilder::dynamic().linvel(Vec2::X), ColliderBuilder::ball(0.5),
);
world.bodies[ball].add_force(Vec2::Y * 20., true);
let committed = world.bodies[ball].try_teleport(
RigidBodyPose { translation: Vec2::new(2., 3.), rotation: Rotation2::default() },
TeleportOptions::new(VelocityPolicy::Clear),
).unwrap();
world.step(1. / 60.);
assert_eq!(world.bodies[ball].translation(), committed.translation);
assert_eq!(world.bodies[ball].linvel(), Vec2::ZERO);
assert_eq!(world.bodies[ball].colliders(), &[child]);