Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm currently trying to implement basketball bouncing into my game using Box2d (jBox2d technically), but I'm a bit confused about restitution.

While trying to create the ball in the testbed first, I've run into infinite bouncing, as described in this question, however obviously not using my own implementation.

The Box2d manual describes restitution as follows:

Restitution is used to make objects bounce. The restitution value is usually set to be between 0 and 1. Consider dropping a ball on a table. A value of zero means the ball won't bounce. This is called an inelastic collision. A value of one means the ball's velocity will be exactly reflected. This is called a perfectly elastic collision.

My confusion lies in that I am still getting infinite bouncing with restitution values at 0.75/0.8. The same behavior can be seen in the testbed under Collision Watching -> Varying Restitution, on the 6th and 7th balls. I believe the last one has restitution of 1, which makes sense, but I don't understand why the second to last ball bounces infinitely (as is happening with my working basketball I've created).

I am looking to understand the restitution concept more fully, as well as look for a solution to infinite bouncing with the Box2d framework. My instinct was to sleep objects that appeared to be moving in very small increments, but this seems like a misuse of the engine. Should I just work with lower restitution values altogether?

share|improve this question
How is your question different from that one you mentioned? It has good answers. – Anko Feb 18 at 22:46
I'm concerned with the restitution value & bouncing specific to Box2d and its mechanics, rather than my own implementation of bouncing. – layzrr Feb 19 at 0:01
On my system 6th ball rapidly lost much of its energy, and then begun bouncing with small amplitude forever. I think, it is some kind of lose-end for box2d. May be, setting some linear damping for the ball can fix it. – Pavel Feb 19 at 8:48

1 Answer

I think you should watch the example you've provided again. The 6th ball does not bounce forever, as if you watch for a long period of time you'll watch it slowly lose energy. (In the latest Chrome, at least). Restitution is exactly what you think it is - the amount of momentum / velocity that is retained upon collision of another object.

share|improve this answer
My results: After about half an hour of running, the second to last ball was still bouncing with a small amplitude. The last ball had actually gained amplitude, so much that it would be off-screen at times. It seems a broken implementation. – Anko Feb 19 at 9:21
The same happened with me as Anko, I left it on for several hours at work, and the second to last ball continued to bounce at a very low amplitude & the last was off screen at its peak. – layzrr Feb 19 at 13:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.