Gravity and lag
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Gravity and lag
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
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
- Puzzlem00n
- Party member
- Posts: 171
- Joined: Fri Apr 06, 2012 8:49 pm
- Contact:
Re: Gravity and lag
I get that, I was the one who linked that answer on this thread earlier. I just don't understand whyNixola 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
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
Code: Select all
function love.update(dt)
dt = math.min(0.1, dt)
......
end
I LÖVE, therefore I am.
Re: Gravity and lag
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:
I'll try a (bad!) example that uses IFs to do the same thing:
I don't think I explained it well, do you understand what I mean?
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
Code: Select all
a = 90
while = function()
a = a - 1
if a > 0 then
while()
end
end
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
- Puzzlem00n
- Party member
- Posts: 171
- Joined: Fri Apr 06, 2012 8:49 pm
- Contact:
Re: Gravity and lag
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!
Thanks a lot, Nixola!
I LÖVE, therefore I am.
Who is online
Users browsing this forum: Bing [Bot], Google [Bot] and 10 guests