Last active
August 29, 2015 14:07
-
-
Save demonixis/aa3c202aae89ae3ef946 to your computer and use it in GitHub Desktop.
CameraFollow script used in my tutorial about Networking with Unity (in French @ http://www.demonixis.net/blog). It's used as a camera component for follow an object.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class CameraFollow : MonoBehaviour | |
{ | |
private Transform _transform; | |
private Quaternion _rotation; | |
public Transform target; | |
public Vector3 offset = new Vector3(0, -5, 10); | |
public float damping = 5; | |
void Awake() | |
{ | |
enabled = false; | |
} | |
void Start () | |
{ | |
_transform = GetComponent<Transform>(); | |
} | |
void LateUpdate() | |
{ | |
_rotation = Quaternion.Euler(target.transform.eulerAngles.x, target.transform.eulerAngles.y, 0); | |
_transform.position = Vector3.Lerp (_transform.position, target.transform.position - (_rotation * offset), Time.deltaTime * damping); | |
_transform.LookAt(target.transform); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment