easy question about collisions

hello again!

i create two static boxes representing some kind of wall. there's no gravity in my world:

Quote:
b2Vec2 gravity(0.0f, 0.0f);
bool doSleep = true;
m_world = new b2World(worldAABB, gravity, doSleep);

b2BoxDef groundBoxDef;

groundBoxDef.extents.Set(800.0f / 2, 20.0f / 2);
groundBoxDef.density = 0.0f;
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(400.0f, 590.0f);
groundBodyDef.rotation = b2_pi / 4;
groundBodyDef.AddShape(&groundBoxDef);
m_world->CreateBody(&groundBodyDef);
groundBodyDef.rotation = -b2_pi / 4;
groundBodyDef.position.Set(400.0f, 10.0f);
groundBodyDef.AddShape(&groundBoxDef);
m_world->CreateBody(&groundBodyDef);


when i create a dynamic body with a circle-shape and throw it against these "walls" the ball moves along these borders. i guess that's because of wall's density of 0 (ball has 1.0f).

my problem is that i want the ball to bounce of the wall and keep the wall-objects static (since they are logically static since they won't move the whole game) - how can i do that?

in pictures:
what i have: http://img248.imageshack.us/my.php?imag ... aveju4.png
what i want: http://img511.imageshack.us/my.php?imag ... antxc7.png

i guess that the solution to this problem may be pretty easy, so any help greatly appreciated! 🙂
When you create the b2CircleDef, set the restitution value to something greater than 0 if you want it to bounce.
Think of restitution value as 'bounciness'.
So 0.0 will be no bounce, 1.0 will make it bounce without losing any velocity, anything greater than 1.0 will gain velocity when it bounces. 😛

So:
Code:
circleDef.restitution = 1.0f;

should do it.

Check out the 'varying restitution' example (VaryingRestitution.h) for an.. example.

Cheers.
-Matt
skatehead wrote:
When you create the b2CircleDef, set the restitution value to something greater than 0 if you want it to bounce.
Think of restitution value as 'bounciness'.
So 0.0 will be no bounce, 1.0 will make it bounce without losing any velocity, anything greater than 1.0 will gain velocity when it bounces. 😛

So:
Code:
circleDef.restitution = 1.0f;

should do it.

Check out the 'varying restitution' example (VaryingRestitution.h) for an.. example.

Cheers.
-Matt

thanks! works like a charm! 🙂

Original thread: https://box2d.org/forum/viewtopic.php?t=113