New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IntegrationParameters passed to ForceGenerator have constant dt #153

kirhgoff opened this Issue Nov 2, 2018 · 3 comments


None yet
2 participants

kirhgoff commented Nov 2, 2018

While playing with nphysics, I modified the example with a stack of blocks so they are affected by force that is changing in time. Here is my code:

impl ForceGenerator<f32> for RoamingForce {
    fn apply(&mut self, params: &IntegrationParameters<f32>, bodies: &mut BodySet<f32>) -> bool {
        if bodies.contains(self.part) {
            let mut part = bodies.body_part_mut(self.part);
            let multiplier = 0.1;
            let center = part.as_ref().center_of_mass();
            let x = multiplier * params.dt.sin();
            let y = multiplier * params.dt.cos();

            let force = Force2::linear(Vector2::new(x, y));


The force generator is simply added to the word for every object:

            let force = RoamingForce::new(handle);

What I see is params.dt is always the same value which looks like to be the default one. I am pretty sure I missed some additional setup for the world, what did I miss?


This comment has been minimized.


sebcrozet commented Nov 3, 2018

Hi! Actually, params.dt is the delta-time used to advance the simulation. That's why it is constant and initially set to 1.0 / 60.0 (assuming the physics world is updated as 60Hz). What you need is the time elapsed in the physics world since the first integration. Right now a way to get this info is to make your force generate accumulate all the dt at each call to apply (self.t += params.dt).

Though it seems useful to add a variable t to the integration parameters so that will be added in the future.


This comment has been minimized.

kirhgoff commented Nov 3, 2018

Thanks, that makes sense.


This comment has been minimized.


sebcrozet commented Nov 17, 2018

Closing this in favor of #157

@sebcrozet sebcrozet closed this Nov 17, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment