Skip to content

Instantly share code, notes, and snippets.

@moon-goon
Created January 24, 2016 04:34
Show Gist options
  • Save moon-goon/41a345b05f6fc34ef704 to your computer and use it in GitHub Desktop.
Save moon-goon/41a345b05f6fc34ef704 to your computer and use it in GitHub Desktop.
public GameObject targetObj;
public float smooth = 1;
Vector3 offsetValue;
void Start() {
offsetValue = transform.position - targetObj.transform.position;
}
void LateUpdate() {
Vector3 initPosition = targetObj.transform.position + offsetValue;
Vector3 position = Vector3.Lerp(transform.position, initPosition, Time.deltaTime * smooth);
transform.position = position;
transform.LookAt(targetObj.transform.position);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment