Skip to content
Snippets Groups Projects
SmootLookAtC.cs 630 B
Newer Older
  • Learn to ignore specific revisions
  • kgingras's avatar
    kgingras committed
    using UnityEngine;
    using System.Collections;
    
    public class SmootLookAtC : MonoBehaviour {
    
    	public Transform target;
    	public float damping = 6.0f;
    	public bool smooth = true;
    
    	// Use this for initialization
    	void Start () {
    	
    	}
    	
    	// Update is called once per frame
    	void LateUpdate () {
    		if (target) {
    			if (smooth)
    			{
    				// Look at and dampen the rotation
    				var rotation = Quaternion.LookRotation(target.position - transform.position);
    				transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * damping);
    			}
    			else
    			{
    				// Just lookat
    				transform.LookAt(target);
    			}
    		}
    	}
    }