Dman_14

RotateFollow

Jan 20th, 2012
103
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var target : Transform; // Assigned via inspector
  2.  
  3. var speed : float=5f;
  4. var rotateSmooth : float=1f;
  5.  
  6. private var controller : CharacterController;
  7. private var myTrans : Transform;
  8.  
  9. function Start () {
  10.        
  11.     myTrans = this.transform;
  12.         controller = GetComponent (CharacterController);
  13.  
  14. }
  15.  
  16. function Update () {
  17.  
  18.         // Find direction
  19.         var direction : Vector3 = target.position-transform.position;
  20.         direction.Normalize ();
  21.  
  22.         controller.Move (direction*speed*Time.deltaTime);
  23.  
  24.     direction.y = 0;
  25.     myTrans.rotation = Quaternion.Slerp (myTrans.rotation, Quaternion.LookRotation (direction), Time.deltaTime * rotateSmooth);
  26.  
  27. }
RAW Paste Data