information on creating a platform game

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: information on creating a platform game

Post by vrld »

You can circumvent the choppy physics problem by using a lower update time limit, like so:

Code: Select all

local min_physics_time_step = 0.04 -- ensure physic framerate to be at least 25fps
function love.update(dt)
    local dt_left = dt
    while dt_left > min_physics_time_step do
        world:update(min_physics_time_step)
        dt_left = dt_left - min_physics_time_step
    end
    world:update(dt_left)

    -- update other stuff
end
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: information on creating a platform game

Post by TechnoCat »

vrld wrote:You can circumvent the choppy physics problem by using a lower update time limit, like so:
<CODE SNIPPET>
Wouldn't this result in an even lower framerate though?
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: information on creating a platform game

Post by BlackBulletIV »

Hmmm... that didn't exactly work for me, it caused other problems (like huge explosions). But I did get it stable with this code:

Code: Select all

local left = rdt
repeat
    self.world:update(0.03) -- I'm using 30 fps here
    left = left - 0.03
until left <= 0.03
Last edited by BlackBulletIV on Fri Jan 14, 2011 1:25 am, edited 1 time in total.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: information on creating a platform game

Post by TechnoCat »

BlackBulletIV wrote:Hmmm... that didn't exactly work for me, it caused other problems (like huge explosions). But I did get it stable with this code:

Code: Select all

local left = rdt
    repeat
        self.world:update(0.03) -- I'm using 30 fps here
        left = left - 0.03
    until left <= 0.03
This is wrong. What if the timestep was less than 0.03? Should it still update the world as if 0.03 seconds took place?
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: information on creating a platform game

Post by BlackBulletIV »

Whoops. Just noticed my error. No wonder it worked though, because this is basically a more bloated version of a fixed frame rate.
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: information on creating a platform game

Post by BlackBulletIV »

This code seems to work fine:

Code: Select all

if dt > maxDelta then
    local left = dt
    while left > maxDelta do
        world:update(maxDelta)
        left = left - maxDelta
    end
else
    world:update(dt)
end
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: information on creating a platform game

Post by TechnoCat »

BlackBulletIV wrote:This code seems to work fine:
Okay, so now you are forgetting the remaining dt less than maxDelta.

This should be what you want.

Code: Select all

local left = dt
if left > maxDelta then
    while left > maxDelta do
        world:update(maxDelta)
        left = left - maxDelta
    end
end
world:update(left)
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: information on creating a platform game

Post by BlackBulletIV »

Unfortunately when I test this I get completely out of the blue explosions that send my boxes flying. That code there is equivalent to vrld's original suggestion, which I had exactly the same problem with. I'm not sure why, but cutting out the world:update(left) call stops the explosions (maybe because left is a very small number? :huh: )
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Milwaukee, WI
Contact:

Re: information on creating a platform game

Post by TechnoCat »

BlackBulletIV wrote:Unfortunately when I test this I get completely out of the blue explosions that send my boxes flying. That code there is equivalent to vrld's original suggestion, which I had exactly the same problem with. I'm not sure why, but cutting out the world:update(left) call stops the explosions (maybe because left is a very small number? :huh: )
All I can think is a scope error making it pass in the wrong value after it loops.
User avatar
BlackBulletIV
Inner party member
Posts: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: information on creating a platform game

Post by BlackBulletIV »

I'm guessing that means that there's two conflicting variables in different scopes?

Another thing I've found that both these methods do is make time faster, though not as fast as it would be without them. It's all very confusing.

EDIT: Oh yeah, here's my latest code:

Code: Select all

local left = dt
if dt > maxDelta then
    while left > maxDelta do
        world:update(maxDelta)
        left = left - maxDelta
    end
    
    world:update(maxDelta)
else
    world:update(dt)
end
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 8 guests