Search code examples
javalibgdxbox2d

setAngularVelocity rotates really slowly


I am using the basic libgdx box2d to manage physics operations of a game. Everything is working properly, except the rotations: even when I set

anyobject.body.setAngularVelocity(someLargeConstant);

the object rotates really slowly(and almost at the same speed) no matter what the 'someLargeConstant' is. Except when I use small numbers for parameter, it can rotate slower. Thus I think I somehow have a maximum angular velocity constant inside my world object, which should be set to some small value.

(I also had a similar issue with linear velocity before and I solved it by adjusting the pixels/meter scale. So its unlikely that the problem is a scaling issue.)

How can I enable the objects to rotate faster?

Here is the code I use:

private static World world = new World(new Vector2(0, 0), true);   //Create a world with no gravity

to create an object I call another class

 public Object(World world, short category, short mask, float x, float y, float radius, Sprite image, 
        float maxSpeed, float frictionStrength, float linearDamping, float angularDamping, boolean movable,
        float elasticity, float mass){

    this.world = world; 
    this.category = category;
    this.mask = mask;
    // We set our body type
    this.bodyDef = new BodyDef();
    if(movable==true){bodyDef.type = BodyType.DynamicBody;}else{bodyDef.type = BodyType.StaticBody;}
    // Set body's starting position in the world
    bodyDef.position.set(x, y);
    bodyDef.linearDamping = linearDamping;
    bodyDef.angularDamping = angularDamping;
    // Create our body in the world using our body definition
    this.body = world.createBody(bodyDef);
    // Create a circle shape and set its radius
    CircleShape circle = new CircleShape();
    circle.setRadius(radius);
    // Create a fixture definition to apply our shape to
    fixtureDef = new FixtureDef();
    fixtureDef.shape = circle;
    fixtureDef.density = (float) (mass/(Math.PI*radius*radius)); 
    fixtureDef.friction = frictionStrength;
    fixtureDef.restitution = elasticity;
    fixtureDef.filter.categoryBits = category;
    fixtureDef.filter.maskBits = mask;
    // Create our fixture and attach it to the body
    this.fixture = body.createFixture(fixtureDef);
    // BodyDef and FixtureDef don't need disposing, but shapes do.
    circle.dispose();

    ... unrelated functions after that
    }

and here I just try to make it rotate fast:

    tempBall.body.setAngularVelocity(20000);

Solution

  • I just found the problem, and it was pretty simple. Im just going to post this here for future googlers:

    Object was actually rotating properly, the problem was in my drawing method, I didn't use conversion between radians to degrees in my batch.draw, and it interpreted everything in radians. I know, such an amateur mistake! Thanks a lot for your time.