Skip to content

Instantly share code, notes, and snippets.

@shadowmint
Created October 6, 2015 03:35
Show Gist options
  • Save shadowmint/8f1f487f189bc359fc67 to your computer and use it in GitHub Desktop.
Save shadowmint/8f1f487f189bc359fc67 to your computer and use it in GitHub Desktop.
public class ChaseCamera : MonoBehaviour {
[Tooltip("The GameObject instance on the scene to match positions with (ie. Don't pick a prefab from the Assets list)")]
public GameObject target;
[Tooltip("Trail this far behind the target")]
public float trailDistance;
[Tooltip("Float this far above the target")]
public float floatHeight;
public void LateUpdate() {
Follow();
}
/// Follow the target
private void Follow() {
if (target != null) {
var pos = target.transform.position;
gameObject.transform.position = pos - trailDistance * target.transform.forward + target.transform.up * floatHeight;
gameObject.transform.LookAt(pos);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment