Bug in love.physics, or bad coding ???

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
apatbol
Prole
Posts: 3
Joined: Tue Apr 12, 2016 7:02 am

Bug in love.physics, or bad coding ???

Post by apatbol »

Hello all,

I am learning Löve & Lua (working with love 10.1), and I have a strange behavior in one of my tests...

I created a ball (associated with an image), a ground and a floor (width: 1/3 of the window, in the middle of the window).
When pressing the space bar, the ball has a vertical kick and goes up. When pressing left or right arrows, the ball goes in the direction of the arrow.
(see attached .love file for the code)

Now, the bug I suspect:
When I start the game, I press one or 2 times (or 3 !) to bring the ball on the floor. Once on the floor, I let the ball few seconds without any move (to "stabilize"). Then I move horizontally with the arrows.
***** the bug ****
sometimes (often..), the ball has no gravity anymore. It stays at the height of the floor, and does not fall on the ground.
when giving a new kick, the ball (if not above the floor) has a "normal" behavior (falling on the ground)
***** bug correction **** (but ugly solution...)
when moving horizontally, I add an impulse to the bottom (with very low impulse: 0.01)
(you can test it by enabling the "correction mode" with up arrow (sorry, I haven't added a debounce mode..)
The strange thing is that if I activate the "correction mode" once, then I haven't the bug anymore...

Now my question:
Did I made a mistake in coding, or is it a bug from love.physics (or is there a ghost in my computer...) ?????

Thanks for your answers

Apatbol
Attachments
Love.physics bug.love
(2.36 KiB) Downloaded 70 times
User avatar
Tanner
Party member
Posts: 166
Joined: Tue Apr 10, 2012 1:51 am

Re: Bug in love.physics, or bad coding ???

Post by Tanner »

Your ball body is going to sleep. You can either wake it up by applying some force to it (like you're doing with the impulse) or you can tell it never to go to sleep.

https://love2d.org/wiki/Body:setSleepingAllowed

Notice the warning on that page: "A sleeping body is not simulated unless it collided with an awake body. Be wary that one can end up with a situation like a floating sleeping body if the floor was removed."

You using `setX` to move your physics body is sort of like if the floor was removed! The body is still asleep because there haven't been any new forces applied to it but now the floor isn't under it anymore.
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Bug in love.physics, or bad coding ???

Post by kikito »

When you think you have found a bug, it is always useful to remember the first rule of programming.
When I write def I mean function.
apatbol
Prole
Posts: 3
Joined: Tue Apr 12, 2016 7:02 am

Re: Bug in love.physics, or bad coding ???

Post by apatbol »

Dear both,

Thanks a lot for the answers !
I apologize, I will not code lazy balls that are sleeping whenever possible, neither I will accuse Löve for my mistakes...
(although I was more expecting a mistake from my side, much more than a bug in Löve..).

Additionnal question as a newbie in game programming: my trick for horizontal move is correct ? or ugly ? (from a "real programmer"'s perspective ?)

Regards

Apatbol
User avatar
Tanner
Party member
Posts: 166
Joined: Tue Apr 10, 2012 1:51 am

Re: Bug in love.physics, or bad coding ???

Post by Tanner »

Personally, I prefer using `Body:applyForce` for moving physics objects like yours. It gives the bodies a nice acceleration/deceleration.

Try it out and if you like it, use it! There's no real right way and I've seen experienced people use both!
apatbol
Prole
Posts: 3
Joined: Tue Apr 12, 2016 7:02 am

Re: Bug in love.physics, or bad coding ???

Post by apatbol »

Hello !

Once again, thanks for the answer.
I'll try it !

Regards

Apatbol
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Amazon [Bot], Majestic-12 [Bot] and 6 guests