Page 1 of 3
Gravity and lag
Posted: Wed Jul 18, 2012 3:11 pm
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.
Thanks.
Re: Gravity and lag
Posted: Wed Jul 18, 2012 9:32 pm
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...
Re: Gravity and lag
Posted: Wed Jul 18, 2012 10:15 pm
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.
Re: Gravity and lag
Posted: Wed Jul 18, 2012 10:34 pm
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
Re: Gravity and lag
Posted: Thu Jul 19, 2012 12:15 am
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
Re: Gravity and lag
Posted: Thu Jul 19, 2012 12:27 am
by Kivutar
Thanks a lot. Now I understand where this bug comes from. I applied this fix in my main.lua update(dt)
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).
Re: Gravity and lag
Posted: Thu Jul 19, 2012 12:32 am
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...
Re: Gravity and lag
Posted: Thu Jul 19, 2012 8:34 am
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).
Re: Gravity and lag
Posted: Thu Jul 19, 2012 9:19 am
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.
Re: Gravity and lag
Posted: Thu Jul 19, 2012 9:27 am
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