pymunk icon indicating copy to clipboard operation
pymunk copied to clipboard

Simplify dt handling in space.step() to encourage a stable dt value

Open viblo opened this issue 6 months ago • 3 comments

Many users that are not experienced with physics engines will believe that the best design is to pass in the frame time (the actual time that passed since the last time step was called) as dt in space.step(dt). However, in Pymunk (and others) its much better if the dt value used is stable, a fixed value. With a stable dt it will be easier for the engine to create a realistic and stable simulation.

However, as of Pymunk 6.x the API of Pymunk does not make this clear, the user should pass in a dt value every time step(dt) is called, and can easy get the impression that it is good if it changes according to actual time passed.

I have two ideas:

  1. Add a default for dt of 1/60.0: def step(self, dt=1/60.0). Minimal changes to the API, should help the user a bit.
  2. Move the dt value to a property on the Space. So you do space = pymunk.Space(dt=1/60), or later `space.dt = 1/60), just like how you deal with gravity.

viblo avatar May 22 '25 19:05 viblo