Making fixed time steps not jerky

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.
Post Reply
Skeletonxf
Citizen
Posts: 87
Joined: Tue Dec 30, 2014 6:07 pm

Making fixed time steps not jerky

Post by Skeletonxf »

My game has very significant bullet time style slow downs and uses love.physics for the physics engine. Initially I opted for a variable time step to let me have easy delta time changes but this caused far too many problems with the physics engine behaving differently so I opted for a fixed time step which I have now fully implemented into the update loop. I am currently testing with a fixed time step of 0.016 seconds. This is ridiculously small because the game can slow down by far more than a factor of 10. However, even with this very small step time the game is visibly jerky due to waiting noticeable lengths of time between two time steps. I think I need to render between time steps so the visuals do not jerk however I am not sure how to do this?

The jerkiness can be seen here:

JoshGrams
Prole
Posts: 33
Joined: Sat May 27, 2017 10:58 am

Re: Making fixed time steps not jerky

Post by JoshGrams »

The general approach is to track two states for all the objects (before and after the last physics step) and interpolate between them based on the "leftover" time. You can also use just the current state and extrapolate into the future based on the velocity and such, but that tends to have more problems. For instance, if an object is going to bounce off a wall next frame, then you will extrapolote into the wall (the wrong direction) and then it will "snap" back to the actual position after the next physics update. So usually it is better to live with the partial physics frame worth of lag.

So if you have the usual update loop where you accumulate time and feed it to the physcis engine in fixed steps:

Code: Select all

function love.update(dt)
    unsimulated = unsimulated + dt
    while unsimulated < fixedStep do
        unsimulated = unsimulated - fixedStep
        savePreviousState(allVisibleObjects)
        world:update(fixedStep)
    end
end
Then when you draw you do (very roughly):

Code: Select all

function love.draw()
    local t = unsimulated / fixedStep  -- between 0 and 1
    for <each object...> do
        x = object.prev.x * (1-t) + object.x * t
        y = object.prev.y * (1-t) + object.y * t
        -- ... etc. ...
    end
end
Does that help?

Also if you're going to slow down that much, you may want to use a shorter fixed timestep, maybe 100 or 120 FPS or even faster instead of only 60? I guess you'd have to test on your slowest target computer with your most complicated level to see how much you can crank it up...

Edit: You may also want to read Gaffer On Games' article Fix Your Timestep if you haven't seen that...
Skeletonxf
Citizen
Posts: 87
Joined: Tue Dec 30, 2014 6:07 pm

Re: Making fixed time steps not jerky

Post by Skeletonxf »

I had indeed read that article and I was still stuck. As I'm using the physics engine I'm very cautious to decrease the time step as fps is already starting to be a concern to me.

Eventually I decided that I don't really need to slow down the game via the time step, I just need to slow down enemies and the player, and I've opted for faking the slow down via :setLinearDamping() instead.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 212 guests