capsloth

Frame rate independent movement

Oct 3rd, 2021 (edited)
1,116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.20 KB | None | 0 0
  1. def move(fps):
  2.     g = 10
  3.     dy = 0
  4.     y = 0
  5.  
  6.     for i in range(fps):
  7.         dy += g * 1/fps
  8.         #y += dy # wrong!
  9.         y += dy * 1/fps # correct
  10.  
  11.     print(round(y))
  12.  
  13. move(30)
  14. move(60)
Add Comment
Please, Sign In to add comment