How to Freeze Quaternion rotation in Y axis
The Code provided, allows the object "from", to rotate and look at the object "target". However, I want to change it so that the object "from" rotates to look at "target" with frozen rotation on Y axis which means that it wont be able to directly look at it due to this restriction.. This is actualy what i want, on the same note, I did try to add a ridigdbody and use the option "freez rotation on Y axis", but that did not work, and i think that is because the script overwrites it..
I am a tottal noob at this Please help me fix my code :)
 public Transform target;
 public Transform from;
 void Update ()
 {
     Example();
     
 }
 void Example()
 {
     Vector3 relativePos = target.position - transform.position;
     Quaternion NewTargetRotation = Quaternion.LookRotation(relativePos);
     transform.rotation = Quaternion.Slerp(from.rotation, NewTargetRotation, Time.deltaTime * 1);
 }
}
$$anonymous$$odify your rotation to lock y like this :
     void Example()
     {
         Vector3 relativePos = target.position - transform.position;
         Quaternion NewTargetRotation = Quaternion.LookRotation(relativePos);
         var angles = NewTargetRotation.eulerAngles;
         angles.y = 0;
         NewTargetRotation = Quaternion.Euler(angles);
         transform.rotation = Quaternion.Slerp(from.rotation,NewTargetRotation, Time.deltaTime * 1);
     }
Answer by Mortalanimal · Sep 24, 2015 at 09:32 AM
thanks a lot, It does the job, but now I face a new problem. I made a video explaining my problem with the link provided to make it more clear :D
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                