- Home /
 
 
               Question by 
               naiboctruk · Nov 25, 2012 at 03:06 PM · 
                rotatedistance  
              
 
              How to make a game charachter rotate towards you when close enough?
like 5 meters in front of him, end then the game charachter rotates towards you. I prefer the javascript code.
Thanks in advance (:
               Comment
              
 
               
              Answer by sirival · Nov 25, 2012 at 04:45 PM
You can create a sphere in your scene, make it a child of the character's game object and mark its collider as a trigger. Set the sphere's collider radius to 5 ( for 5 meters ). Then place a script on the sphere that will contain the following code:
 function OnTriggerEnter( Collider other )
 {
      transform.parent.LookAt( other.transform.position );
 }
 
              Your answer