9

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
  • 1,165
  • 2
  • 10
  • 15
  • 2
    I know that, thanks. But we are doing computer science, a physics engine is supposed to allow you to change the standard physics. And I would like my circle not to rotate. – Undo Jan 26 '13 at 13:13

3 Answers3

25

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

Pavel
  • 2,602
  • 1
  • 27
  • 34
  • 1
    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. – Undo Jan 26 '13 at 14:34
  • 1
    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. – Pavel Jan 26 '13 at 17:08
  • Using .SetFixedRotation(true) on the Body (not the BodyDef) worked in box2dweb. – Deepak Joy Cheenath Jul 25 '13 at 16:30
4

In the runtime you want to set set rotationfixed then

b2Body body;  
body->SetFixedRotation(true);
Singhak
  • 8,508
  • 2
  • 31
  • 34
0

Fixed rotation means rotation at fixed axis in physics,so isFixedRotation=true; may not solve this problem,but setting angular damping to such a high value can prevent from rotating

Kharak
  • 62
  • 8