- Home /
 
              This post has been wikified, any user with enough reputation can edit it. 
            
 
             
               Question by 
               bakkoto · Feb 07, 2015 at 01:04 AM · 
                rotationquaternionangle  
              
 
              Check if rotation (only on Y axis) of some object toward another is finshed?
Hi there. I already know that simmilar questions have been asked before but it´s kinda different from what Im trying to achieve. In my case the two gameobjects in question (attacker and target) could have different Y positions (different heights) see the Picture below (Imagine that the Unit B is a flying Dragon in this case) :

Each time a unit attack, first it face the target and do damage then the target face the attacker after the damage has been done (simillar to a classic Turn based game)
In order to make Units facing each other, here is my rotation code :
 public void Step()
 {
  Vector3 targetPoint = this.observerObject.position - this.targetToLookAt.position;
  Quaternion newRotation = Quaternion.LookRotation(-targetPoint, Vector3.up);
  newRotation.x = 0; // to rotate only around Y axis 
  newRotation.z = 0; // to rotate only around Y axis 
  this.observerObject.rotation = Quaternion.Slerp(this.observerObject.rotation,newRotation, Time.deltaTime * this.rotationSpeed);
 }
 
               And to check if the rotation is done, I tried first :
 if (Quaternion.Angle(this.observerObject.rotation, newRotation) <= 0.1f)
 {
   finished = true;
 }
 
               And also :
 if((newRotation.eulerAngles - this.observerObject.rotation.eulerAngles).sqrMagnitude <= 0.1)
 {
   finished = true;
 }
 
               Both approaches works fine but only when Unit A and B have the same Y position. Any help would be greatly appreciated.
 
                 
                unbenannt.png 
                (120.5 kB) 
               
 
              
               Comment
              
 
               
              Your answer