Created
July 9, 2016 12:17
-
-
Save madebynoxc/445b8a01890f3c230706b65e4083b20f to your computer and use it in GitHub Desktop.
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
var target : Transform; | |
var distance = 3.0; | |
var height = 3.0; | |
var damping = 5.0; | |
var smoothRotation = true; | |
var rotationDamping = 10.0; | |
var lockRotation :boolean; | |
private var cam; | |
function Start(){ | |
cam = Camera.main; | |
} | |
function Update () { | |
var wantedPosition = target.TransformPoint(-0, height, -distance); | |
transform.position = Vector3.Lerp (transform.position, wantedPosition, Time.deltaTime * damping); | |
if (smoothRotation) { | |
var wantedRotation = Quaternion.LookRotation(target.position - transform.position, target.up); | |
transform.rotation = Quaternion.Slerp (transform.rotation, wantedRotation, Time.deltaTime * rotationDamping); | |
} | |
else transform.LookAt (target, target.up); | |
if (lockRotation){ | |
transform.localRotation = Quaternion.Euler(0,0,0); | |
} | |
if (Input.GetKey(KeyCode.Equals)){ // back | |
if (cam.orthographicSize > 5){ | |
cam.orthographicSize -= 0.5; | |
} | |
} | |
if (Input.GetKey(KeyCode.Minus)){ // forward | |
if (cam.orthographicSize < 12){ | |
cam.orthographicSize += 0.5; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment