On the steering of flying objects

Well I’ve been struggling for a while but I still can’t figure out how to get the wings to tilt when the flying object turns.

This video shows how the tank’s steering is currently meeting my expectations.

``````    @Override
protected void controlUpdate(float tpf) {
if (spatial != null) {
if (i < move.size() - 1) {

Vector3f currentPoint = spatial.getLocalTranslation();
Vector3f nextPoint = move.get(i + 1);
// Calculate the step of the node towards the next point
Vector3f step = nextPoint.subtract(currentPoint).normalizeLocal().multLocal(tpf).multLocal(50f);

Vector3f directionToTarget = nextPoint.subtract(currentPoint).normalizeLocal();

Quaternion rotation=spatial.getLocalRotation();
targetQua.lookAt(step, new Vector3f(0,1,0));
rotation.nlerp(targetQua, 0.1f);
float GoalAngle = Math.abs(spatial.getLocalRotation().dot(targetQua));
// System.err.println("相似度：" + GoalAngle);

// Check if you have reached the next point getLocalTranslation
float distanceToNextPoint = spatial.getWorldTranslation().distance(nextPoint);
// System.err.println(distanceToNextPoint);
if (distanceToNextPoint < 0.2f ) {
//If the next point has been reached, update the current path index
i++;
}

}
}
}
``````

I’m currently using this code to move.

Use this code to complete the turn

``````                Quaternion rotation=spatial.getLocalRotation();
targetQua.lookAt(step, new Vector3f(0,1,0));
rotation.nlerp(targetQua, 0.1f);
``````

How do I tilt while steering and level when I’m done(Steer like an aeroplane.)?

``````//Please point out any confusion about my questions.
``````

Up vector is 0,1,0 so of course up is always going to point exactly up. You could use a different up vector but probably you want to combine a roll rotation with this rotation.

For example:

``````// 45 degree roll
Quaternion roll = new Quaternion().fromAngles(0, 0, FastMath.QUARTER_PI);
rotation = rotation.mult(roll);
``````
3 Likes

Thanks for the quick reply, I’m going to try it now

1 Like