- Home /
 
 
               Question by 
               littledude194 · Dec 06, 2014 at 06:28 AM · 
                2d3dmodelquad  
              
 
              How to make quad's always face player?
I want the pre-modeled quad to always look at the player, because we are making a game that has somewhat the same aspects as DOOM. In DOOM the enemy's are all 2d so they all face the charater. I think that I just need to add a javascript or something but I dont know how. Please help.
Thanks
               Comment
              
 
               
              Answer by jenci1990 · Dec 06, 2014 at 08:01 AM
Attach this javascript to the quad:
 public var isReverse = true;
 
 function Update () {
     if (Camera.main) {
         var cameraTransform = Camera.main.gameObject.transform;
         transform.LookAt(cameraTransform);
         if (isReverse) transform.forward *= -1;
     }
 }
 
               If you can't see the quad change the "isReverse" variable.
Answer by psycocrusher · Dec 06, 2014 at 05:39 PM
Put this on the object, z has to point towards the player, the target is the player.
 var target : Transform;
 
 function Update () {
     
     // Rotate towards target    
     var targetPoint = target.position;
     targetPoint.y = transform.position.y;
     
     var targetRotation = Quaternion.LookRotation (targetPoint - transform.position, Vector3.up);
     transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * 2.0);
 }
 
              Your answer