Advertisement
dermetfan

fixed timestep accumulator

Sep 14th, 2015
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.34 KB | None | 0 0
  1. private float accumulator = 0;
  2.  
  3. // when setting up the world
  4. world.setAutoClearForces(false);
  5.  
  6. @Override
  7. public void update(float delta) {
  8.     float step = 1 / 60f; // the duration of each timestep
  9.     accumulator += delta;
  10.  
  11.     while(accumulator - step >= 0) {
  12.         accumulator -= step;
  13.         world.step(step, 8, 3);
  14.     }
  15.  
  16.     world.clearForces();
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement