25.7 C
New York
Thursday, August 14, 2025

Ought to physics substepping embody your entire replace or solely collision decision + constraint resolving?


I am engaged on a easy physics simulation and I need to use substeps to enhance stability. I’m not sure whether or not I ought to apply substeps to your entire physics replace or simply to collision decision.

First, within the main-loop/game-loop I replace the physics engine a hard and fast variety of occasions per second so to make the physics system unbiased of what {hardware} it’s working on. I do that like so (as per this reply from one other thread):

whereas ... {
    // occasion dealing with...

    // physics...
    physics_acc += dt;                       // dt = how lengthy the final body took in seconds
    whereas physics_acc >= PHYSICS_TIMESTEP {  // PHYSICS_TIMESTEP = 1.0 / 60.0
        solver.remedy(&mut particle_system);
        physics_acc -= PHYSICS_TIMESTEP;
    }

    // rendering...
}

Again to the updating of the physics system, listed here are the 2 approaches I’m interested by:

Choice 1 – full replace per substep iteration

// solver.remedy(...)
for _ in 0..self.substeps {
    self.apply_gravity(ps);
    self.update_positions(ps);
    self.resolver.detect_and_resolve(ps);
    self.constrain_to_window(ps);
}

Choice 2 – substep just for collision detection+decision and constraint resolving

// solver.remedy(...)
self.apply_gravity(ps);
self.update_positions(ps);
for _ in 0..self.substeps {  
    self.resolver.detect_and_resolve(ps);
    self.constrain_to_window(ps);
}

What are the sensible variations between these approaches? Particularly, I’m inquisitive about:

I’d respect perception into which strategy is usually most popular and why.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles