I'm working on a game using Phys2d with great pleasure so far, but I've now run into a problem that gives me serious headaches.
In a simple test world, I set up a static box (a floor so to speak) and an object falling down on it.
While all works well without any restitution set on the bodies, it's rather boring without any bounciness.
However, as soon as I set a restitution on the bodies (1.f on the floor, 0.5f on the object, but I found the values to be completely irrelevant concerning this issue), it seems as if there never comes the point where the world considers the "bouncing" energy to be zero. In fact, after a while, it increases again and stays almost constant at something very low.
Enough, however, to make my engine update the pixel position and so the object swaps between two positions, constantly hopping 1 (and sometimes even 2 or 3, very random!) pixel up and down and up and down... and it will not stop.
I can't seem to fix this problem, only setting a restitution to zero does, and that, of course, kills the bouncing.
Here's what I've tried:
- Setting the world damping to different values
Doesn't change a thing. A low value will nullify the bounce eventually, but the popping still occurs!
- Set the body's damping.
Won't help, will only make the thing fall more slowly, or - if I set it too high - will start to fly away against my gravitiy...
- Giving frictions to the bodies.
The objects both have a dummy friction of 0.5. Didn't change a thing for me, also played with the friction and it won't help. Would have been too werid if it helped, anyway.
- Using different gravity values, doing more world steps per frame.
I use 200.f because it feels right with my 60fps. Each frame I do a world step by 1 / 60 time units. Playing with this hasn't changed a thing.
- Altering the object's mass.
Should not help but I tried it anyway, setting it to stuff between 0 and 1000, and it doesn't help.
- Use enableRestingBodyDetection.
Either I missed the purpose of that function or it doesn't work at all. At least it never had any effect at all for me, even if setting the tresholds to astronomical values bodies will never rest or anything.
- Avoid rounding my position values for drawing.
This would be an optical workaround but never a fix. The position still changes, but you can't really see it unless you look very close.
I will refuse to use this workaround, as I'm rendering using OpenGL and using unround position values will result in sprite filtering, that looks crappy.
So, I believe I'm missing something very obvious, but since I took the demos as my reference and therefore practically based my world off of it (just with a different time stepping), I just can't see what.
When the bouncing energy gets low enough, I expect a body to not bounce at all after a while, not even minimally. It should simply rest and do nothing unless a new force acts on it.
I mean, if you let a pen fall down it won't continue to pop up and down from the floor a millimeter, it'll just lay there flat after bouncing once or maybe twice.
Maybe the gravity pulls it down causing a new little bounce? If that's the case, that would be a bug.
Thanks for any help in advance.