我一直在做一个自上而下的汽车游戏已经有一段时间了,它似乎总是能够正确地做一件事.在我的实例中,它正确地完成了我的汽车物理.
我的当前轮换无法正常处理我遇到了问题.我知道问题在于我的幅度为0,同时乘以Math.cos/sin方向,但我根本不知道如何解决它.
这是当前的底层代码.
private void move(int deltaTime) {
double secondsElapsed = (deltaTime / 1000.0);// seconds since last update
double speed = velocity.magnitude();
double magnitude = 0;
if (up)
magnitude = 100.0;
if (down)
magnitude = -100.0;
if (right)
direction += rotationSpeed * (speed/topspeed);// * secondsElapsed;
if (left)
direction -= rotationSpeed * (speed/topspeed);// * secondsElapsed;
double dir = Math.toRadians(direction - 90);
acceleration = new Vector2D(magnitude * Math.cos(dir), magnitude * Math.sin(dir));
Vector2D deltaA = acceleration.scale(secondsElapsed);
velocity = velocity.add(deltaA);
if (speed < 1.5 …Run Code Online (Sandbox Code Playgroud)