如何阻止矢量运动

时间:2017-08-18 06:02:34

标签: java

我制作了这个程序,玩家通过按钮使用向量从起点移动到终点(我将引用"带终点的RedDot)。玩家移动到终点完全正常,但不是停在它移动经过的点。正如你在我的更新函数中看到的那样,向量运动。

 public void update(float dt) {

    if (InputManager.isTriggered(KeyEvent.VK_ENTER)) {
        enter += 1;
    }
    if (InputManager.isTriggered(KeyEvent.VK_BACK_SPACE)) {
        enter -= 1;
    }

    if (enter == 1) {

        Vec2 direction = new Vec2(0.0f, 0.0f);
        direction.setX(-RedDot.getPositionX() - 100);
        direction.setY(RedDot.getPositionY() - 100);
        direction.normalize();
        CloudPlayer.setVelocity(Vec2.scale(direction, speed));
    }

}

我尝试过在一定时间后改变速度变量但是它没有工作

0 个答案:

没有答案