pub struct IntegrationParameters {Show 13 fields
pub dt: f32,
pub min_ccd_dt: f32,
pub contact_softness: SpringCoefficients<f32>,
pub warmstart_coefficient: f32,
pub length_unit: f32,
pub normalized_allowed_linear_error: f32,
pub normalized_max_corrective_velocity: f32,
pub normalized_prediction_distance: f32,
pub num_solver_iterations: usize,
pub num_internal_pgs_iterations: usize,
pub num_internal_stabilization_iterations: usize,
pub min_island_size: usize,
pub max_ccd_substeps: usize,
}Expand description
Configuration parameters that control the physics simulation quality and behavior.
These parameters affect how the physics engine advances time, resolves collisions, and maintains stability. The defaults work well for most games, but you may want to adjust them based on your specific needs.
§Key parameters for beginners
dt: Timestep duration (default: 1/60 second). Most games run physics at 60Hz.num_solver_iterations: More iterations = more accurate but slower (default: 4)length_unit: Scale factor if your world units aren’t meters (e.g., 100 for pixel-based games)
§Example
// Standard 60 FPS physics with default settings
let mut integration_params = IntegrationParameters::default();
// For a more accurate (but slower) simulation:
integration_params.num_solver_iterations = 8;
// For pixel-based 2D games where 100 pixels = 1 meter:
integration_params.length_unit = 100.0;Most other parameters are advanced settings for fine-tuning stability and performance.
Fields§
§dt: f32The timestep length - how much simulated time passes per physics step (default: 1.0 / 60.0).
Set this to 1.0 / your_target_fps. For example:
- 60 FPS:
1.0 / 60.0≈ 0.0167 seconds - 120 FPS:
1.0 / 120.0≈ 0.0083 seconds
Smaller timesteps are more accurate but require more CPU time per second of simulated time.
min_ccd_dt: f32Minimum timestep size when using CCD with multiple substeps (default: 1.0 / 60.0 / 100.0).
When CCD with multiple substeps is enabled, the timestep is subdivided
into smaller pieces. This timestep subdivision won’t generate timestep
lengths smaller than min_ccd_dt.
Setting this to a large value will reduce the opportunity to performing CCD substepping, resulting in potentially more time dropped by the motion-clamping mechanism. Setting this to an very small value may lead to numerical instabilities.
contact_softness: SpringCoefficients<f32>Softness coefficients for contact constraints.
warmstart_coefficient: f32The coefficient in [0, 1] applied to warmstart impulses, i.e., impulses that are used as the
initial solution (instead of 0) at the next simulation step.
This should generally be set to 1.
(default 1.0).
length_unit: f32The scale factor for your world if you’re not using meters (default: 1.0).
Rapier is tuned for human-scale objects measured in meters. If your game uses different units, set this to how many of your units equal 1 meter in the real world.
Examples:
- Your game uses meters:
length_unit = 1.0(default) - Your game uses centimeters:
length_unit = 100.0(100 cm = 1 m) - Pixel-based 2D game where typical objects are 100 pixels tall:
length_unit = 100.0 - Your game uses feet:
length_unit = 3.28(approximately)
This automatically scales various internal tolerances and thresholds to work correctly with your chosen units.
normalized_allowed_linear_error: f32Amount of penetration the engine won’t attempt to correct (default: 0.001m).
This value is implicitly scaled by IntegrationParameters::length_unit.
normalized_max_corrective_velocity: f32Maximum amount of penetration the solver will attempt to resolve in one timestep (default: 10.0).
This value is implicitly scaled by IntegrationParameters::length_unit.
normalized_prediction_distance: f32The maximal distance separating two objects that will generate predictive contacts (default: 0.002m).
This value is implicitly scaled by IntegrationParameters::length_unit.
num_solver_iterations: usizeThe number of solver iterations run by the constraints solver for calculating forces (default: 4).
Higher values produce more accurate and stable simulations at the cost of performance.
4(default): Good balance for most games8-12: Use for demanding scenarios (stacks of objects, complex machinery)1-2: Use if performance is critical and accuracy can be sacrificed
num_internal_pgs_iterations: usizeNumber of internal Project Gauss Seidel (PGS) iterations run at each solver iteration (default: 1).
num_internal_stabilization_iterations: usizeThe number of stabilization iterations run at each solver iterations (default: 1).
min_island_size: usizeMinimum number of dynamic bodies on each active island (default: 128).
max_ccd_substeps: usizeMaximum number of substeps performed by the solver (default: 1).
Implementations§
Source§impl IntegrationParameters
impl IntegrationParameters
Sourcepub fn inv_dt(&self) -> f32
pub fn inv_dt(&self) -> f32
The inverse of the time-stepping length, i.e. the steps per seconds (Hz).
This is zero if self.dt is zero.
Sourcepub fn set_dt(&mut self, dt: f32)
👎Deprecated: You can just set the IntegrationParams::dt value directly
pub fn set_dt(&mut self, dt: f32)
IntegrationParams::dt value directlySets the time-stepping length.
Sourcepub fn set_inv_dt(&mut self, inv_dt: f32)
pub fn set_inv_dt(&mut self, inv_dt: f32)
Sets the inverse time-stepping length (i.e. the frequency).
This automatically recompute self.dt.
Sourcepub fn allowed_linear_error(&self) -> f32
pub fn allowed_linear_error(&self) -> f32
Amount of penetration the engine won’t attempt to correct (default: 0.001 multiplied by
Self::length_unit).
Sourcepub fn max_corrective_velocity(&self) -> f32
pub fn max_corrective_velocity(&self) -> f32
Maximum amount of penetration the solver will attempt to resolve in one timestep.
This is equal to Self::normalized_max_corrective_velocity multiplied by
Self::length_unit.
Sourcepub fn prediction_distance(&self) -> f32
pub fn prediction_distance(&self) -> f32
The maximal distance separating two objects that will generate predictive contacts
(default: 0.002m multiped by Self::length_unit).
Trait Implementations§
Source§impl Clone for IntegrationParameters
impl Clone for IntegrationParameters
Source§fn clone(&self) -> IntegrationParameters
fn clone(&self) -> IntegrationParameters
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for IntegrationParameters
impl Debug for IntegrationParameters
Source§impl Default for IntegrationParameters
impl Default for IntegrationParameters
Source§impl PartialEq for IntegrationParameters
impl PartialEq for IntegrationParameters
impl Copy for IntegrationParameters
impl StructuralPartialEq for IntegrationParameters
Auto Trait Implementations§
impl Freeze for IntegrationParameters
impl RefUnwindSafe for IntegrationParameters
impl Send for IntegrationParameters
impl Sync for IntegrationParameters
impl Unpin for IntegrationParameters
impl UnwindSafe for IntegrationParameters
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.