Skip to content

Instantly share code, notes, and snippets.

@omikun
Created July 11, 2017 19:04
Show Gist options
  • Save omikun/088c489871e970188aa113f869f1b3a5 to your computer and use it in GitHub Desktop.
Save omikun/088c489871e970188aa113f869f1b3a5 to your computer and use it in GitHub Desktop.
Follows target like in flight sim
//taken from https://github.com/razvanilin/Nebulae/blob/master/Assets/Scripts/CameraMovement.cs
using UnityEngine;
using System.Collections;
public class CameraMovement : MonoBehaviour {
public Transform target;
public float distance = 2.0f;
public float height;
public float heightDamping = 2.0f;
public float rotationDamping = 3.0f;
private Quaternion oldRotation;
private Quaternion targetRotation;
private Vector3 relTargetPos;
// Use this for initialization
void Start () {
oldRotation = target.rotation;
}
void FixedUpdate()
{
if (!target)
return;
targetRotation = target.rotation;
Quaternion currentRotation = Quaternion.Lerp(oldRotation, targetRotation, rotationDamping * Time.deltaTime);
oldRotation = currentRotation;
transform.position = target.transform.position;
transform.position -= currentRotation * Vector3.forward * distance;
transform.LookAt(target, target.TransformDirection(Vector3.up));
}
}
Contact GitHub API Training Shop Blog About
© 2017 GitHub, Inc. Terms Privacy Security Status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment