Created
July 11, 2017 19:04
-
-
Save omikun/088c489871e970188aa113f869f1b3a5 to your computer and use it in GitHub Desktop.
Follows target like in flight sim
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
//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