【问题标题】:LibGDX - Box2D: move object without speed restriction using MouseJointLibGDX - Box2D:使用 MouseJoint 移动没有速度限制的对象
【发布时间】:2013-07-02 15:04:08
【问题描述】:

我正在使用 MouseJoint 来拖动对象。但是物体的移动太慢了。

我需要以鼠标的速度移动它们。目前,我将这些设置用于MouseJointDef

MouseJointDef def = new MouseJointDef();
def.bodyA = groundBody;
def.bodyB = hitBody;
def.collideConnected = true;
def.target.set(testPoint.x, testPoint.y);
def.maxForce = 10000.0f * hitBody.getMass();
def.frequencyHz=100;
def.dampingRatio=0;

还有这些用于正文:

 Body box = world.createBody(def);
 MassData mass = new MassData();
 mass.mass=100;
 //mass.I=1; What is it???
 mass.center.set(width/2, height/2);
 box.setMassData(mass);

我该怎么办?

【问题讨论】:

    标签: box2d libgdx physics game-engine


    【解决方案1】:

    如果您的游戏宽度和高度太大,例如 800x480 或其他东西,则将其除以 40,例如... 20x12 ....

    这是因为 box2d 的速度限制为 2 个单位。而你想要的是每个时间步更多的单位,但你的屏幕太大而无法实现..所以如果你缩短你的世界,那么速度问题就会得到解决。

    【讨论】:

    • 我的错误是我在创建具有正确参数的相机实例后使用了this.cam.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());! :) 谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-24
    • 2020-05-14
    相关资源
    最近更新 更多