dac2009
dac2009

Reputation: 3561

Ball in JBox2d bounces forever

Im trying out JBox2d. I´ve been through a couple of tutorials, and got it up and running. Created four walls and a ball that should bounch. At the start the ball would bounce too little, just making 2-3 bounces then stopping suddenly. I managed to figure out this was due to:

/**
 * A velocity threshold for elastic collisions. Any collision with a
 * relative linear velocity below this threshold will be treated as
 * inelastic.
 */
public static float velocityThreshold = 1.0f;

in the Settings. I tried fiddle with the value, and setting it to 0 seems to make it look real (I'm having it at 0.1 now since I guess 0 would be bad..). However, it bounces correctly a few times, getting lower and lower velocity, but then it reaches a point where it will simply continue bouncing forever. I have tried changing the mass, density, friction and restitution of the ball and world but nothing seems to help (If I set the ball restitution to < 0.2 it will stop, or at least look as if has stopped, I'm not sure what JBox2D thinks, I think its still working on sorting out the bouncing). Does anyone know how to fix this so that the ball will stop bouncing in the end?

Upvotes: 2

Views: 753

Answers (1)

Daniel Murphy
Daniel Murphy

Reputation: 882

You're messing with the wrong value. Take a look at your fixture definition, there's a value for restitution there. Check out the restitution test in the testbed for an example.

That value is for comparison in general for all the physics objects.

Upvotes: 1

Related Questions