Box2D Forums

It is currently Sat Apr 19, 2014 12:34 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Restitution - Question
PostPosted: Fri Apr 15, 2011 8:24 pm 
Offline

Joined: Fri Apr 15, 2011 8:17 pm
Posts: 3
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.


Top
 Profile  
 
PostPosted: Sat Apr 16, 2011 5:15 am 
Offline

Joined: Mon Nov 01, 2010 4:02 pm
Posts: 52
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.


Top
 Profile  
 
PostPosted: Sat Apr 16, 2011 9:02 am 
Offline

Joined: Fri Apr 15, 2011 8:17 pm
Posts: 3
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


Top
 Profile  
 
PostPosted: Tue Apr 19, 2011 6:06 am 
Offline

Joined: Fri Apr 15, 2011 8:17 pm
Posts: 3
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.


Top
 Profile  
 
PostPosted: Sat Apr 23, 2011 3:44 pm 
Offline
Site Admin

Joined: Thu Sep 06, 2007 12:34 am
Posts: 2946
You cannot get a perfect rebound due to position correction when shapes overlap.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: Exabot [Bot], Yahoo [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group