Search code examples
javabox2dgame-physicsjbox2d

Prevent body from rotating in Box2D


I am currently using Box2d, more precisely the Java port jBox2d.

I have a circle that is colliding with other circles when falling (all those circles form a kind of a crank, see picture below).

illustration

Naturely, the circle begins to rotate when falling. But I would like to prevent it from rotating so that the friction is much higher.


Solution

  • To prevent body from rotating set fixedRotation = true at BodyDef or call setFixedRotation of Body (if you need run-time change behavior).