I have a space fighter AI. I need to determine how to pitch, yaw and roll the craft to aim at the target.
My current solution:
To obtain the Yaw angle to position the target above the fighter, here are my steps:
- Project the target vector onto the local XZ plane of the fighter.
- Vector3.Angle(transform.forward, projectedVector)
The problem is that Vector3.Angle always return a positive angle
^ T T ^ |/ \| F F (F - Fighter, ^ - forward, T - Target)
both of these return the same angle
My current solution is to
- Cross product
- Dot the result against
- if < 0, its one direction, where > 0 its the other. (switchable)
Same is done with roll and pitch
This current solution does too much computation. Doing a stress test with ~300 units slows the simulation down to sub 30 FPS on a 3 year old computer. (I am assuming that players will have older computers)
Is there a better way to obtain the direction of an angle without needing to do all these?