Page 1 of 1

how to use dt in platformers movement?

Posted: Sun Aug 25, 2013 9:53 am
by mazino
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:

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 
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*

Re: how to use dt in platformers movement?

Posted: Sun Aug 25, 2013 10:15 am
by Robin
First of all, you need to multiply gravity by dt as well, otherwise the acceleration is frame-rate dependent.

This might resolve your issue, but it might not. If it doesn't resolve it, we'd like to take a look at your .love, because that really helps us help you.

Re: how to use dt in platformers movement?

Posted: Sun Aug 25, 2013 2:25 pm
by mazino
Oh yes that was what was making it vary so much, woops :P. It still has a bit of variance when it gets very laggy but I figure i can cap the jumping height of the jump. Although it probably isn't necessary.

thanks a lot. btw sorry for posting in the wrong forum. didn't realize until now.

Re: how to use dt in platformers movement?

Posted: Sun Aug 25, 2013 6:38 pm
by Jeeper
mazino wrote:Oh yes that was what was making it vary so much, woops :P. It still has a bit of variance when it gets very laggy but I figure i can cap the jumping height of the jump. Although it probably isn't necessary.

thanks a lot. btw sorry for posting in the wrong forum. didn't realize until now.
How do you manage to get it too lagg in the first place?