setAngularVelocity旋转得很慢 [英] setAngularVelocity rotates really slowly

查看:277
本文介绍了setAngularVelocity旋转得很慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用基本的libgdx box2d来管理游戏的物理操作.除了旋转以外,一切都正常工作:即使我设置了

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);

无论"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?

这是我使用的代码:

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);

推荐答案

我刚刚发现了问题,这很简单.我只是要在这里发布此邮件,以供将来的Google员工使用:

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

对象实际上正在正确旋转,问题出在我的绘制方法中,我未在batch.draw中使用弧度到度之间的转换,而是以弧度来解释所有内容.我知道,这是一个业余错误!非常感谢您的宝贵时间.

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.

这篇关于setAngularVelocity旋转得很慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆