So I was able to get mouse "click to move" working in the little project that I'm trying out. However, what's eluding me now is getting my model to lean while it's turning towards it's destination.
So far, I've got this as the main engine for the movement:
private static class shipMoveController extends Controller {
private static final long serialVersionUID = 1L;
private final Ship ship;
private Vector3f desiredLocation;
private boolean moving;
private final Vector3f upAxis = new Vector3f(0, 1, 0);
private final Vector3f temp = new Vector3f();
public shipMoveController(final Ship ship) {
this.ship = ship;
}
public void setDesiredLocation(final Vector3f location) {
desiredLocation = location;
moving = true;
}
public Vector3f getDesiredLocation() {
return desiredLocation;
}
@Override
public void update(final float time) {
if (!moving) {
return;
}
final Vector3f directional = desiredLocation.subtract(ship
.getLocalTranslation(), temp);
ship.updateWorldVectors();
ship.getLocalRotation().lookAt(directional, upAxis);
final float length = directional.length();
if (length < 5) { // if it's around x units
ship.deccelerate(time);
moving = false;
return;
}
float shipFlyDistance = ship.getVelocity() * time;
if (shipFlyDistance > length) {
shipFlyDistance = length;
}
directional.multLocal(shipFlyDistance / length);
ship.accelerate(time);
ship.getLocalTranslation().addLocal(directional);
}
}
The ship.getLocalRotation().lookAt(directional, upAxis); is the meat of it all right now, but it turns the model really quickly into the direction of interest and the model starts to accelerate. The behavior I want is for:
a) the user to click a desired location (already defined with Rays etc)
b) the model to start moving in the current direction.
c) the model to gently turn in the direction of the location of interest (based on some turn rate parameter).
...any ideas?
Was thinking of some kind of while statement to check the angle of the model's current heading to the location of interest, but I'm confused how that would work.
Any help would be appreciated.
Thanks,
D