Bouncing indefinitely?

Incrediblue
Posts: 2
Joined: Fri Jan 15, 2010 10:03 pm

Bouncing indefinitely?

Post by Incrediblue »

Does anyone know what friction and restitution values I should use if I want a sphere to bounce indefinitely on a flat section of my terrain collision object? I read that the restitution values are multiplied every time two objects collide, so if both are set to 1 the ball should bounce forever, right? Unfortunately, these values make the ball bounce higher and higher.

Gravity: Standard -9.82
Sphere: Friction (Tried 0, 0.5 and 1.0), Restitution (1.0), Mass (1), Radius (1.0)
Terrain: Friction (Tried 0, 0.5 and 1.0, Restitution (1.0), Static triangle collision object (Very low-poly)
Engine: SIO2 (for iPhone)

The closest I get to a more or less stable bounce height is with restitution values of 0.96, but even then the sphere will sometimes bounce higher and other times lower than the starting position...

I realise that I may be bending the rules here and that Bullet probably wasn't designed for this, but if anyone knows of a solution, I'd be grateful if they could let me know :)

Thanks in advance.
-Incrediblue
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Bouncing indefinitely?

Post by Erwin Coumans »

Bullet doesn't preserve energy, so bouncing forever won't work out-of-the-box.

There are some ways to improve this. Enabling 'split impulse' avoids adding energy during penetration recovery, see http://bulletphysics.org/mediawiki-1.5. ... SolverInfo


Still, you will need to adjust the velocity (kinetic energy) manually to keep the total energy constant. It is best to adjust this manually each frame, after running 'stepSimulation' (calculate potential (height) and kinetic (velocity) energy, and adjust it).
Thanks,
Erwin
Incrediblue
Posts: 2
Joined: Fri Jan 15, 2010 10:03 pm

Re: Bouncing indefinitely?

Post by Incrediblue »

Thanks for the info, Erwin - that's much appreciated :)