I am attempting to design mouse-aimed turning to control an aircraft in a 3D environment. To cut it short, you aim where you want to go, and the aircraft turns to face that direction (similar to War Thunder).

When turning an aircraft, it makes sense to use your elevator instead of your rudder (especially in long turns). If you need to turn 90 degrees left, it makes sense to roll 90 degrees left first, then use the elevator to turn, finally leveling out the aircraft once the target heading is reached.

Now, I want the user to be able to control the roll, but I also want the game to do it automatically when the player is not controlling it. My problem is conceptualizing what operations I need to do to get the target roll angle.

I managed to figure out that to align myself correctly, I need to align the plane that bisects the aircraft (the V plane) with the direction I want to move to (the D vector). The R angle is how much I would need to turn (in local angles) to achieve the derired orientation.

So, if I the player looks at the blue circle, the plane will roll right and hold that roll until it's almost aligned with the desired direction. At that point, it will unroll and level out.

Just figuring out the roll I need would be a big help. Preferably I'd like to get it done with dot and cross products, as these operations are already established and I have easy access to the up, right and forward vectors of the plane, as well as the direction vector.


I once solved the problem in a way that sounds fake but feels surprisingly good:

Mouse controls pitch and yaw, relative to the horizon. Roll is just a visual effect determined automatically by the current angular velocity. In other words, flying a curve makes the plane bank, not the other way around.


While Philipp's suggestion works quite well, it wasn't quite enough for me, so after giving it some thought I found a definitive solution.

Finding the roll angle is actually not that difficult: I start by removing the forward component from the direction vector (red). I can then compute the dot product between this vector (green) and the world up vector (purple) (0,0,1) or (0,1,0), depending on your convention.

The roll angle is the inverse cosine of the result (assuming all vectors are normalized) times the sign of the dot product between the right vector if the roll were 0 (purple vector below) and the green vector from the drawing above. This last part defines which side the plane is actually turning to.

enter image description here

In my experience this works flawlessly! The plane aligns itself perfectly with where you want to go.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.