Created
October 6, 2015 03:35
-
-
Save shadowmint/8f1f487f189bc359fc67 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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