How to convert a 3D direction into yaw and pitch commands?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ghsoares

Hello!

I’m creating a 3D space game with ships, where I control then using Yaw and Pitch to maneuver. And I’m creating a context-based steering behaviour that chooses a direction to follow as enemy AI. I’m using C# because I’m more used to it in terms of OOP that GDScript.

Basically, I watched a devlog from Game Endeavor: https://www.youtube.com/watch?v=6BrZryMz-ac (The Trick I Used to Make Combat Fun! | Devlog), where he explains that he used a context-based steering bevahiour in the enemies AI to follow the player in a more complex pattern, trying to avoid obstacles, getting away from the player or circle around the player when is close enough.

So I made a AI to my game that follows the player when is a bit far, and circles around the player when is close enough. All of this only changing the yaw and pitch of the ship.

The problem is that I need to convert somehow the direction into Yaw and Pitch commands, ranging from -1 to 1, that latter is remapped to -[yaw/pitch]speed to [yaw/pitch]speed.

What I already have is a AI that follows a target, but is a bit unstable. There is some situations where the ships goes up or down too much, while the yaw remains stable.

I can’t explain very well what is happened and what is the expected bevahiour, maybe testing my project is better: https://github.com/ghsoares/Space-Game/tree/master