private class ShipControl extends Behavior {
@Override
public void update() {
Vector3 up = Vector3.yAxis();
Vector3 right = Vector3.xAxis();
Vector3 forward = Vector3.zAxis().negate();
Motion m = getBehavior(Motion.class);
float yaw = -getMouseDX() * mouseSensitivity;
float pitch = getMouseDY() * mouseSensitivity;
if (isKeyDown(KEY_UP)) {
pitch += 50;
}
if (isKeyDown(KEY_DOWN)) {
pitch -= 50;
}
if (isKeyDown(KEY_LEFT)) {
yaw += 50;
}
if (isKeyDown(KEY_RIGHT)) {
yaw -= 50;
}
yaw = Math.min(Math.abs(yaw), 120) * Math.signum(yaw);
pitch = Math.min(Math.abs(pitch), 120) * Math.signum(pitch);
rot = rot.rotate(up, yaw * Time.deltaTime());
rot = rot.rotate(right, pitch * Time.deltaTime());
if (isKeyDown(KEY_A)) {
rot = rot.rotate(forward, -90 * Time.deltaTime());
}
if (isKeyDown(KEY_D)) {
rot = rot.rotate(forward, 90 * Time.deltaTime());
}
float thrust = 00.0f;
if (isKeyDown(KEY_W)) {
thrust = 20.0f;
} else if (isKeyDown(KEY_S)) {
thrust = -20.0f;
}
m.velocity = rot.applyRotation(new Vector3(0, 0, -thrust));
centerMouse();
}