I am currently developing a game for Android, and I would like your experience on the problem that I had.
Background:
My game includes a motion independent of the frame rate, which takes into account the value of the delta time before performing the necessary speed calculations.
The game is a traditional 2D platformer.
Problem:
Here is my question (simplified). Let it pretend that my character is a square standing on top of the platform (in this case, “gravity” is the constant downward speed of the VelocityDown symbol).
I defined collision detection as follows (assuming the Y axis is down):
Given characterFootY is the y-coordinate of the base of my square character, platformSurfaceY is the top y-coordinate of my platform and platformBaseY strong> is the bottom y-coordinate of my platform:
if (characterFootY + characterVelocityDown > platformSurfaceY && characterFootY + characterDy < platformBaseY) {
//Collision Is True
characterFootY = platformSurfaceY;
characterVelocityDown = 0;
} else{
characterVelocityDown = deltaTime * 6;
This approach works great when the game runs at normal speed; however, if the game slows down, deltaTime (elapsed time between the previous frame and the current frame) becomes large and characterFootY + characterVelocityDown exceeds the boundaries that determine the collision detection, and the character simply falls straight (as if teleporting).
How can I approach this problem to prevent this?
Thank you in advance for your help, and I look forward to learning from you!