Original Post
I noticed that my game runs a bit differently when running at 60 FPS on my PC and 30 FPS on my phone, and I traced it down to the friction code. I'm applying friction like this:
The results are not consistent between 60 Hz and 30 Hz. But then I thought about how continuous compound interest is calculated, and I came up with this:
It works perfectly, at least on paper. Has anyone else ever used an approach like this? Or is there a better way to do it?
Edit: I should mention that the game is using a fixed time step. At 30 Hz it's 1/30 seconds and at 60 Hz it's 1/60.
newVelocity = oldVelocity - oldVelocity * friction * elapsedTimeThe results are not consistent between 60 Hz and 30 Hz. But then I thought about how continuous compound interest is calculated, and I came up with this:
newVelocity = oldVelocity * exp(-friction * elapsedTime)It works perfectly, at least on paper. Has anyone else ever used an approach like this? Or is there a better way to do it?
Edit: I should mention that the game is using a fixed time step. At 30 Hz it's 1/30 seconds and at 60 Hz it's 1/60.