Page 2 of 3

Re: information on creating a platform game

Posted: Thu Jan 13, 2011 8:57 pm
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

Re: information on creating a platform game

Posted: Thu Jan 13, 2011 10:18 pm
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?

Re: information on creating a platform game

Posted: Fri Jan 14, 2011 1:03 am
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

Re: information on creating a platform game

Posted: Fri Jan 14, 2011 1:08 am
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?

Re: information on creating a platform game

Posted: Fri Jan 14, 2011 1:27 am
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.

Re: information on creating a platform game

Posted: Fri Jan 14, 2011 1:44 am
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

Re: information on creating a platform game

Posted: Fri Jan 14, 2011 1:48 am
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)

Re: information on creating a platform game

Posted: Fri Jan 14, 2011 1:56 am
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: )

Re: information on creating a platform game

Posted: Fri Jan 14, 2011 1:58 am
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.

Re: information on creating a platform game

Posted: Fri Jan 14, 2011 2:05 am
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