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.
Kivutar
Prole
Posts: 13
Joined: Wed Jul 18, 2012 2:49 pm

Gravity and lag

Post by Kivutar »

Dear Löve users,

I'm facing a bug i've not been able to fix for a few days.

My game is a platformer, I use HC for collisions.
Here is the problem:
When my game lags too much (the first time I launch it on a linux session, or on windows when I launch two instances of the game), my objects with gravity go throug the ground!

The bug seams not due to HC, because I tried to debut by adding a print(self.y) in my character class, and when the bug appears, the first value to be printed is huge like 1900, instead of 300 when the bug does not appears.

I also tried to put JIT off, but it did not fix.

You can browse the code here https://github.com/Kivutar/twinsisters
I also attach my love file.
twinsisters.love
(7.49 MiB) Downloaded 260 times
Thanks.
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 »

Tunneling it's a bad, bad thing. When the framerate is too low, your player falls under the ground in 1 frame, so the normal collision detection can't stop it... I remember there's a way to prevent it (setting the object as 'bullet' or something like that), but I don't remember if it's on HC or love.physics...
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Kivutar
Prole
Posts: 13
Joined: Wed Jul 18, 2012 2:49 pm

Re: Gravity and lag

Post by Kivutar »

Thanks for your reply.

What do you mean by tunneling? Sorry, my english is bad.

Is the bullet trick the body type "kinematic" in Box2D: https://love2d.org/wiki/BodyType ? Because I searched HC reference for such a thing and found nothing.

There must be a way to avoid that. I suppose there is a lot of platformers made with HC. What is the right way to handle it? I read a lot of code from the forum and my gravity system seamed to be the most common way to implement a platformer engine.

Also, many forum members advice to not use love.phisics for simple platformers, and HC is said to be the best collision lib for high speed bodies.
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 »

I explained what tunneling is:
When the framerate is too low, your player falls under the ground in 1 frame, so the normal collision detection can't stop 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 »

This problem really isn't Hard-On Collider exclusive. I actually had this problem a long time ago, and even though I wasn't using HC, the solution still applies. Read thoroughly: viewtopic.php?f=4&t=8740
I LÖVE, therefore I am.
Kivutar
Prole
Posts: 13
Joined: Wed Jul 18, 2012 2:49 pm

Re: Gravity and lag

Post by Kivutar »

Thanks a lot. Now I understand where this bug comes from. I applied this fix in my main.lua update(dt)

Code: Select all

dt = math.min(dt, 0.07)
And any idea why my game lag so much on windows? It runs at 40 FPS wih windows, and 60 FPS on Linux, same laptop (macbook).
User avatar
Puzzlem00n
Party member
Posts: 171
Joined: Fri Apr 06, 2012 8:49 pm
Contact:

Re: Gravity and lag

Post by Puzzlem00n »

Interesting... I myself am on windows, and I decided to check to see how much lag there really was, and it doesn't even open. All other .loves do open, though. Something weird is going on with this thing...
I LÖVE, therefore I am.
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Gravity and lag

Post by coffee »

Puzzlem00n wrote:Interesting... I myself am on windows, and I decided to check to see how much lag there really was, and it doesn't even open. All other .loves do open, though. Something weird is going on with this thing...
Well I use OSX and game opens (no player visible). Since my recent platform testing experience I noticed that in same machine dt OS time behaves different at loading/first moments. OSX and XP works ok for me. Win7/Win8 acts in another way. That leads that something dropping/airborne at start is not caught right away and ends outside screen.

Kivutar, I feel I'm having a kind of problem like you with this viewtopic.php?f=4&t=10042. First attachment there don't "work" with W7/W8 and I had to fix start position the "player" in ground at start (instead of funny drop).
Kivutar
Prole
Posts: 13
Joined: Wed Jul 18, 2012 2:49 pm

Re: Gravity and lag

Post by Kivutar »

Yes I think our bugs have the same cause.

Maybe having a title screen will be a natural workaround to this bug.

Here is the fixed .love file. Puzzlem00n can you test it please? It lauches well on my win7.
twinsisters.love
(7.49 MiB) Downloaded 386 times
coffee
Party member
Posts: 1206
Joined: Wed Nov 02, 2011 9:07 pm

Re: Gravity and lag

Post by coffee »

Kivutar wrote:Yes I think our bugs have the same cause.

Maybe having a title screen will be a natural workaround to this bug.

Here is the fixed .love file. Puzzlem00n can you test it please? It lauches well on my win7.
twinsisters.love
It launches well (and player is show dropping) in snow leopard too. I'm happy that you had same idea of parachute player :)
But I add that I tested an older version taken from your git and already was working well before. Only the new .love taken from this thread had the "hidden" (beneath the ground?) player
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], MrFariator and 159 guests