else if (velocityInputTime < 0)
targetSpeed -= 0.5f;
// Velocity
Vector3f currentVelocity = new Vector3f(vehicleControl.getLinearVelocity());
Quaternion currentRotation = new Quaternion(vehicleControl.getPhysicsRotation());
Vector3f targetVelocity = currentRotation.mult(new Vector3f(0f, 0f, targetSpeed));
float xDiff = currentVelocity.x - targetVelocity.x;
float zDiff = currentVelocity.z - targetVelocity.z;
Vector3f diffVector = new Vector3f(xDiff, 0f, zDiff);
// diffVector nach z drehen
diffVector = currentRotation.inverse().mult(diffVector);
float zThrust = 0f, yThrust, xThrust = 0f;
float engine = .1f, thrust = .1f;
if (diffVector.z < 0) { // accelerate
zThrust = (-diffVector.z > engine) ? engine : -diffVector.z;
} else if (diffVector.z > 0) { // brake
zThrust = (diffVector.z > engine) ? -engine : -diffVector.z;
}
if (diffVector.x < 0) { // accelerate
xThrust = (-diffVector.x > engine) ? engine : -diffVector.x;
} else if (diffVector.x > 0) { // brake
xThrust = (diffVector.x > engine) ? -engine : -diffVector.x;
}
Vector3f hemisphereVector = new Vector3f(0f, 0f, 1f);
hemisphereVector = currentRotation.multLocal(hemisphereVector);
xThrust = (hemisphereVector.x > 0) ? xThrust : xThrust;
zThrust = (hemisphereVector.z > 0) ? zThrust : zThrust;
Vector3f impulse = new Vector3f(xThrust, 0f, zThrust);
vehicleControl.applyImpulse(currentRotation.mult(impulse), Vector3f.ZERO);
// // Velocity
// System.out.println(vehicleControl.getPhysicsRotation().mult(v));
// System.out.println("tar: " + targetVelocity);