- Home /
 
Convert directions in Vector3 to yaw/pitch/(roll),Converting directions in Vector3d to yaw/pitch/(roll)
I'm trying to implement a AI ship in a space flight simulator. Basically the AI ship attempts to shoot at the player's ship by moving towards the expected position of the player's ship. My code so far is:
  private void chaseTarget(Transform target)
     {
         // calculate expected position of target
         Vector3 pos = target.position;
         Vector3 vel = target.GetComponent<Rigidbody>().velocity;
 
         float dist = Vector3.Distance(this.transform.position, target.position);
         float leadTime = dist / gunspeed;
         Vector3 expectedPOS = pos + leadTime * vel;
 
         // calculating heading to target
         Vector3 heading = expectedPOS - this.transform.position;
 ...
 
               Basically I calculate the player's ship's expected position, and i want to point this ship(ai one) towards that position. The direction is represented by the Vector3 but I need to convert this to yaw/pitch and maybe roll.
How do you implement this? I've tried converting the Vector3 to a Quaterion and then using formulas from wikipedia to break it down into yaw/pitch but it is not working ,
               Comment
              
 
               
              Your answer