how to use dt in platformers movement?
Posted: Sun Aug 25, 2013 9:53 am
Hello, I'm trying to make a platformer game, and I've done the basics, walking and jumping. I use a gravity variable to add to the vertical speed every frame basically. The position is modified by the vertical speed. I multiply vertical speed by dt in order to keep the movement somewhat independent from frame lag. So the game feels smoother. It works, when the fps drops the game continues to work relatively smoothly.
Here's the problem:
I noticed that the jumping isn't consistent. Sometimes it jumps a bit more than others or a bit less. Which is very troublesome in a platformer game. I'm not sure if my implementation is wrong, or If I need to do something more in order to get past this, or simply using dt for movement in platformers isn't ideal in general.
This is my code for the player class:
What's your opinion on this? Thanks for replying.
*I searched the forums but i couldn't find anything, perhaps I'm bad at searching tho :S*
Here's the problem:
I noticed that the jumping isn't consistent. Sometimes it jumps a bit more than others or a bit less. Which is very troublesome in a platformer game. I'm not sure if my implementation is wrong, or If I need to do something more in order to get past this, or simply using dt for movement in platformers isn't ideal in general.
This is my code for the player class:
Code: Select all
self.vspeed = self.vspeed + self.gravity --adds gravity every step
self.dx = self.x
self.dy = self.y
self.x = self.x + self.hspeed*dt
self.y = self.y + self.vspeed*dt --changes the position of the character
*I searched the forums but i couldn't find anything, perhaps I'm bad at searching tho :S*