Understanding restitution

Jul 25, 2011 at 9:22 PM

I'm having a hard time with restitution in my game.

I have a ball that has restitution set at 1 since I want it to bounce.
Then I have an object with restitution set at 0.

The desired effect is that the ball would bounce and the object would stay still. However, the object just slides when it gets hit by the ball.
How do I keep the object still? I can't use a joint or use a static body because I need to make the object move.

Jul 25, 2011 at 10:19 PM

maybe you can increase this object's mass?

Jul 26, 2011 at 12:26 PM

Increasing the mass would help, as serioussam909 said. Alternatively try bumping up the linear drag. The only problem with linear drag is it will also effect how your shape will move. I think changing the mass is the easiest solution.

Jul 26, 2011 at 1:00 PM
Edited Jul 26, 2011 at 1:00 PM

Filter the collisions, and when you detect a collision betwen this two objects run this code.

objectyouwantnottoreact.BodyType = BodyType.Static;

objectyouwantnottoreact.BodyType = BodyType.Dynamic;

Hopefully this would make it static just the needed time to not react to the collision and allow to move freely. However, if the object is moving while the contact this method would look weird.

Jul 26, 2011 at 2:01 PM

Thanks for the replies.

I opted for the mass setting. It seems to keep the object static if the mass is really high.

I'll keep the other tips in mind however for future solutions.

Again, thanks for the help. 

Jul 26, 2011 at 7:27 PM

Thats weird, I was playing a bit with my game and noticed in some of my levels the game would start to freeze and every object would teleport out of the screen.

if I comment out "object.Mass = float.MaxValue;" it seems to go away.

Is there a limit to set the mass at?