PhysicsPipeline

Struct PhysicsPipeline 

Source
pub struct PhysicsPipeline {
    pub counters: Counters,
    /* private fields */
}
Expand description

The main physics simulation engine that runs your physics world forward in time.

Think of this as the “game loop” for your physics simulation. Each frame, you call PhysicsPipeline::step to advance the simulation by one timestep. This structure handles all the complex physics calculations: detecting collisions between objects, resolving contacts so objects don’t overlap, and updating positions and velocities.

§Performance note

This structure only contains temporary working memory (scratch buffers). You can create a new one anytime, but it’s more efficient to reuse the same instance across frames since Rapier can reuse allocated memory.

§How it works (simplified)

Rapier uses a time-stepping approach where each step involves:

  1. Collision detection: Find which objects are touching or overlapping
  2. Constraint solving: Calculate forces to prevent overlaps and enforce joint constraints
  3. Integration: Update object positions and velocities based on forces and gravity
  4. Position correction: Fix any remaining overlaps that might have occurred

Fields§

§counters: Counters

Counters used for benchmarking only.

Implementations§

Source§

impl PhysicsPipeline

Source

pub fn new() -> PhysicsPipeline

Creates a new physics pipeline.

Call this once when setting up your physics world. The pipeline can be reused across multiple frames for better performance.

Source

pub fn step( &mut self, gravity: &Vector<f32>, integration_parameters: &IntegrationParameters, islands: &mut IslandManager, broad_phase: &mut BroadPhaseBvh, narrow_phase: &mut NarrowPhase, bodies: &mut RigidBodySet, colliders: &mut ColliderSet, impulse_joints: &mut ImpulseJointSet, multibody_joints: &mut MultibodyJointSet, ccd_solver: &mut CCDSolver, hooks: &dyn PhysicsHooks, events: &dyn EventHandler, )

Advances the physics simulation by one timestep.

This is the main function you’ll call every frame in your game loop. It performs all physics calculations: collision detection, constraint solving, and updating object positions.

§Parameters
  • gravity - The gravity vector applied to all dynamic bodies (e.g., vector![0.0, -9.81, 0.0] for Earth gravity pointing down)
  • integration_parameters - Controls the simulation quality and timestep size (typically 60 Hz = 1/60 second per step)
  • islands - Internal system that groups connected objects together for efficient solving (automatically managed)
  • broad_phase - Fast collision detection phase that filters out distant object pairs (automatically managed)
  • narrow_phase - Precise collision detection that computes exact contact points (automatically managed)
  • bodies - Your collection of rigid bodies (the physical objects that move and collide)
  • colliders - The collision shapes attached to your bodies (boxes, spheres, meshes, etc.)
  • impulse_joints - Regular joints connecting bodies (hinges, sliders, etc.)
  • multibody_joints - Articulated joints for robot-like structures (optional, can be empty)
  • ccd_solver - Continuous collision detection to prevent fast objects from tunneling through thin walls
  • hooks - Optional callbacks to customize collision filtering and contact modification
  • events - Optional handler to receive collision events (when objects start/stop touching)
§Example
// In your game loop:
physics_pipeline.step(
    &vector![0.0, -9.81, 0.0],  // Gravity pointing down
    &integration_parameters,
    &mut islands,
    &mut broad_phase,
    &mut narrow_phase,
    &mut bodies,
    &mut colliders,
    &mut impulse_joints,
    &mut multibody_joints,
    &mut ccd_solver,
    &(),  // No custom hooks
    &(),  // No event handler
);

Trait Implementations§

Source§

impl Default for PhysicsPipeline

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts 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>

Converts 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)

Converts &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)

Converts &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
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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 more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.