Gravity and lag

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
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Gravity and lag

Post by Nixola »

If the dt is too high, the moving object could pass through other objects in only one frame, without the collision being detected. Updating the world more times with smaller dt helps to prevent it
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Puzzlem00n
Party member
Posts: 171
Joined: Fri Apr 06, 2012 8:49 pm
Contact:

Re: Gravity and lag

Post by Puzzlem00n »

Nixola wrote:If the dt is too high, the moving object could pass through other objects in only one frame, without the collision being detected. Updating the world more times with smaller dt helps to prevent it
I get that, I was the one who linked that answer on this thread earlier. I just don't understand why

Code: Select all

function love.update(dt)
    local physics_dt = dt
    while physics_dt > 0 do
        physics_update(math.min(0.1, physics_dt))
        physics_dt = physics_dt - 0.1
    end
end
Is better than

Code: Select all

function love.update(dt)
    dt = math.min(0.1, dt)
    ......
end
I don't understand in part because I don't get what that first code block is even doing. While loops are sort of foreign to me (as far as I can tell, they do the same thing as if statements). Sorry, should've been clearer before.
I LÖVE, therefore I am.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Gravity and lag

Post by Nixola »

The former will repeat the update many times every frame with small dts, the latter will update only once per frame, decreasing dt if it's too highso slowing the game if the framerate is low


Anyway, the whiles are like ifs, but they "freeze" everything else until their condition is false. Example:

Code: Select all

a = 90
while a > 0 do
   a = a - <
   print(a)
end
I'll try a (bad!) example that uses IFs to do the same thing:

Code: Select all

a = 90
while = function()
   a = a - 1
   if a > 0 then
      while()
   end
end
I don't think I explained it well, do you understand what I mean?
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Puzzlem00n
Party member
Posts: 171
Joined: Fri Apr 06, 2012 8:49 pm
Contact:

Re: Gravity and lag

Post by Puzzlem00n »

Well, that clears up while statements. I guess that code then is allowing everything to update at the amount it should, but not all at once to account for things moving through others. Now that I get it, I see it's actually pretty clever.

Thanks a lot, Nixola!
I LÖVE, therefore I am.
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 10 guests