Prevent body from rotating in Box2D

10,075

Solution 1

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

Solution 2

In the runtime you want to set set rotationfixed then

b2Body body;  
body->SetFixedRotation(true);
Share:
10,075
Undo
Author by

Undo

Updated on July 21, 2022

Comments

  • Undo
    Undo almost 2 years

    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.

  • Undo
    Undo over 11 years
    Actually, I tried all fixedRotation = true and angularDamping and everything you would imagine on the BodyDef object but nothing worked. Though, I finally manage to get it working by using setAngularDamping(200) on the body object itself on runtime. I may try setFixedRotation on the body object as well.
  • Pavel
    Pavel over 11 years
    Looks like you doing smth wrong, fixed rotation MUST work. Check density of your fixture, it must be more then zero. I had such trouble because of this thing.
  • Deepak Joy Cheenath
    Deepak Joy Cheenath almost 11 years
    Using .SetFixedRotation(true) on the Body (not the BodyDef) worked in box2dweb.