how to use dt in platformers movement?

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
mazino
Prole
Posts: 2
Joined: Sun Aug 25, 2013 9:39 am

how to use dt in platformers movement?

Post 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*
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: how to use dt in platformers movement?

Post 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.
Help us help you: attach a .love.
mazino
Prole
Posts: 2
Joined: Sun Aug 25, 2013 9:39 am

Re: how to use dt in platformers movement?

Post 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.
User avatar
Jeeper
Party member
Posts: 611
Joined: Tue Mar 12, 2013 7:11 pm
Contact:

Re: how to use dt in platformers movement?

Post 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?
Post Reply

Who is online

Users browsing this forum: Amazon [Bot] and 3 guests