Restitution - Question

Here's the place to get help and discuss features. The focus is on the C++ version, but generic questions are welcome.
Lexxion
Posts: 3
Joined: Fri Apr 15, 2011 8:17 pm

Restitution - Question

Postby Lexxion » Fri Apr 15, 2011 8:24 pm

Hello all,

I am learning Box2D and I like it a lot. I have a problem with a simple object bouncing of the floor.
I understand that setting restitution to 1.0f will make the object bounce to the same height (is this assumption correct?). What happens to me is the object keeps bouncing higher and higher. I would like it to bounce to the height I dropped it from.

I created a static body (set as edge) around the screen. I set gravity to 0.f, 9.8f. I created a ball as dynamic body and density = 1.0f, friction=0.0f, restitution = 1.0f.

What is that I am missing here?

Any help would be appreciated.

Thanks.

mkfield
Posts: 52
Joined: Mon Nov 01, 2010 4:02 pm

Re: Restitution - Question

Postby mkfield » Sat Apr 16, 2011 5:15 am

9.8f should be -9.8f if you want downwards gravity. I don't know if 1.0f restitution will make the ball bounce to the same height, I think 1.0f means the object is perfectly elastic but gravity will still do its job. You may need to apply an impulse or force of some kind to keep the bounce height the same.

Lexxion
Posts: 3
Joined: Fri Apr 15, 2011 8:17 pm

Re: Restitution - Question

Postby Lexxion » Sat Apr 16, 2011 9:02 am

The gravity works ok. The ball bounces ok. But every time it bounces higher and higher. There are no forces applied. If I set restitution to lets say 0.9f then every bounce will be lower than the previous one. I just don't know what settings should be applied to make the ball bounce to the same height every time.

Any more suggestions?

Thanks

Lexxion
Posts: 3
Joined: Fri Apr 15, 2011 8:17 pm

Re: Restitution - Question

Postby Lexxion » Tue Apr 19, 2011 6:06 am

After more testing I found out a way to keep the ball bouncing to the same height (for a long time). I found out that if you have:

Gravity: +/- 9.8f The ball restitution should be: 0.9875f
Gravity: +- 15.0f The ball restitution should be: 0.9845f

The ball will bounce to approximately the same height but after a while it might drop just a little bit. I think this is the closest I can get the ball to jump to same height.

Erin Catto
Site Admin
Posts: 2948
Joined: Thu Sep 06, 2007 12:34 am

Re: Restitution - Question

Postby Erin Catto » Sat Apr 23, 2011 3:44 pm

You cannot get a perfect rebound due to position correction when shapes overlap.


Return to “General Discussion”



Who is online

Users browsing this forum: Bing [Bot] and 4 guests