1
\$\begingroup\$

I'm trying to get an understanding for the Box2D/Farseer physics engine by implementing a small air hockey simulation. There, I have the problem that the CPU player attacks the puck, kicks it, but also gets kicked back due to restitution. I would like the CPU player's mallet to be pinned to where it currently is; being able to kick others, but not getting kicked by something else.

I have tried setting its restitution to 0 but restitution is always the maximum of the two colliding bodies and as the puck has a restitution of 0.9, the mallet will also move.

I have also tried changing the mass of the mallet to a insanely high value but this influences damping again.

What is the best approach to really pin it afte collision?

\$\endgroup\$
1
\$\begingroup\$

I have tried setting its restitution to 0 but restitution is always the maximum of the two colliding bodies and as the puck has a restitution of 0.9, the mallet will also move.

I thought you came to conclusion that this was not true in the comment in another question?

Anyways the only thing I can think of is to use a sensor.

On BeginContact disable the body and set the Body.Position manually to a location beside the mallet. To pass/shoot I would sets its velocity in what ever direction and then re-enable the puck after its a certain radius distance from the player.

\$\endgroup\$
1
  • \$\begingroup\$ Yeah, I seem to have been wrong about the restitution. It really is using the max. Your idea brought me to the following solution: I added a collision handler. If it collides with the puck, the LinearVelocity is set to 0. This prevents bouncing and stops the mallet. Thanks for the hint with the velocity. \$\endgroup\$
    – Krumelur
    Feb 17 '12 at 21:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .