Prevent body from rotating in Box2D
Asked Answered
I

3

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.

Ignominious answered 26/1, 2013 at 12:47 Comment(1)
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.Ignominious
C
25

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

Comradery answered 26/1, 2013 at 13:38 Comment(3)
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.Ignominious
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.Comradery
Using .SetFixedRotation(true) on the Body (not the BodyDef) worked in box2dweb.Tannenwald
I
4

In the runtime you want to set set rotationfixed then

b2Body body;  
body->SetFixedRotation(true);
Idolatry answered 21/11, 2013 at 12:14 Comment(0)
W
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

Woke answered 4/9, 2016 at 16:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.