Hi all,
I’m having some problems when using the conventional method of making movement framerate independent. I’m using Time.deltaTime in Update() to compensate for slower framerate when adding or subtracting movement related values, but there seems to be something wrong with my code which makes my character jump in different y speed even though I’m multiplying the gravity with Time.deltaTime.
The code below is reduced to its core functionality. When the jump reaches apex the y value of the characters position varies quite a lot when the framerate is fluctuating.
You say “when the framerate is fluctuating” and “big difference” - these are pretty subjective. What numbers are you seeing, and what do you expect?
Your code is correct, but if you’re getting huge variations in framerate it’s quite possible for one frame to take so long to process that you miss part of the jump’s apex. For instance you could skip from +1u/s to -1u/s, completely missing the 0u/s speed, and ending up with your apex marked at the point where you had +/-1u/s (a lower point). There’s no reason for you to code around this in a video game (though it’s possible) - you want to get rid of the fluctuation instead.
You’ve probably already done this, but it’s a good idea to also go through your script and double-check that nothing else is modifying your vertical speed value.