- Home /
 
               Question by 
               Borgo · Jan 29, 2011 at 08:02 PM · 
                rotationquaternionlookat  
              
 
              How can I get the rotation between two objects
Hi,
I want to do something like this:
- I have a Player;
- I have a enemy;
- The enemy smooth look at the player
How can I get the rotation of the enemy based on the player position?
 In others words, I want to get 0 angle when the enemy is exactly facing to the player.
I try this but doen't works as I expect:
var rot : Quaternion;
rot.SetFromToRotation(transform.position,target.position);
print(rot.y - transform.rotation.y);
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Borgo · Jan 29, 2011 at 08:52 PM
I got it works making this:
I created an empty object named lookTo and add as child of enemy.
Use this script:
lookTo.LookAt(target);
var a = (Mathf.Sign(lookTo.rotation.y)*lookTo.rotation.y) - (Mathf.Sign(transform.rotation.y)*transform.rotation.y);
print( a*Mathf.Sign(a) );
Your answer
 
 
             Follow this Question
Related Questions
Rotation Reset 0 Answers
How to clamp the rotation of this? 0 Answers
Using Quaternion.LookRotation( ) on y axis only, but keep x axis of transform the same? 2 Answers
"Look rotation viewing vector is zero" error 2 Answers
Transform.LookAt and Back! 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                