I need to fix the dynamic body position so that it would not rotate and would not move even if there are other forces, collisions and so on. Let me first explain why I need this.

I have a dynamic body which is the game character. There are non-moving objects that the game character should land on and get some energy as long the character is in contact with those bodies. As these bodies are non-moving it would be natural to make them Static or Kinematic. But in my case I cannot do that, as far as there is another Kinematic body with which all the game items should be collided and on EndCollision event those items should be removed. But in Box2D static and kinematic bodies don't collided with each other. So I have to make my game item on which the character should land Dynamic but still should be sure that it will not move. How should I do this?


One way to do this is create a kinematic body for each dynamic body as a 'shadow' body, with exactly the same fixtures. After very time step, set the position, angle, linear velocity and angular velocity of the kinematic body to match that of the dynamic body it is shadowing.

The original dynamic fixture should be set to not collide with its own shadow fixture, and not to collide with the original fixtures for bodies that have a shadow body.

When two sets of bodies like this collide, their shadow bodies will prevent the opposing dynamic body from pushing them, but they can still collide normally with other fixtures in the world.

Keep in mind that Box2D tries really hard to replicate the physics we see in the real world, and what you are asking for here is not realistic at all. You will probably see some VERY weird behavior, especially if you try to pile these bodies up together, even though they follow your rules. However, for a top-down scenario where piling of bodies is not needed, it might be ok.

| improve this answer | |
  • \$\begingroup\$ Thanks for the answer, but I don't understand what I ask which is strange. :) \$\endgroup\$ – Narek Feb 9 '15 at 5:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.