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
Bug in love.physics, or bad coding ???
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Bug in love.physics, or bad coding ???
- Attachments
-
- Love.physics bug.love
- (2.36 KiB) Downloaded 70 times
Re: Bug in love.physics, or bad coding ???
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.
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.
- 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 ???
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.
Re: Bug in love.physics, or bad coding ???
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
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
Re: Bug in love.physics, or bad coding ???
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!
Try it out and if you like it, use it! There's no real right way and I've seen experienced people use both!
Re: Bug in love.physics, or bad coding ???
Hello !
Once again, thanks for the answer.
I'll try it !
Regards
Apatbol
Once again, thanks for the answer.
I'll try it !
Regards
Apatbol
Who is online
Users browsing this forum: Amazon [Bot], Bing [Bot], Google [Bot] and 8 guests