diff options
Diffstat (limited to 'FPSCarCam.cs')
-rw-r--r-- | FPSCarCam.cs | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/FPSCarCam.cs b/FPSCarCam.cs new file mode 100644 index 0000000..3905c84 --- /dev/null +++ b/FPSCarCam.cs @@ -0,0 +1,42 @@ +using UnityEngine; + +public class FPSCarCam : MonoBehaviour +{ + public Rigidbody rig; + + public float movementAmount = 1f; + + public float returnAmount = 1f; + + public float friction = 0.9f; + + private Vector3 cameraVelocity; + + private Vector3 lastRigVelocity; + + private Vector3 startPos; + + private WobbleShake shake; + + private void Start() + { + startPos = base.transform.localPosition; + shake = base.transform.root.GetComponentInChildren<WobbleShake>(); + } + + private void Update() + { + Vector3 vector = rig.velocity - lastRigVelocity; + cameraVelocity -= vector; + cameraVelocity -= cameraVelocity * Time.deltaTime * friction; + Vector3 vector2 = base.transform.parent.TransformPoint(startPos) - base.transform.position; + cameraVelocity += vector2.normalized * Mathf.Pow(vector2.magnitude, 2f) * Time.deltaTime * returnAmount; + base.transform.position += cameraVelocity * Time.deltaTime * movementAmount; + base.transform.rotation = Quaternion.Lerp(base.transform.rotation, rig.rotation, 10f * Time.deltaTime); + lastRigVelocity = rig.velocity; + } + + private void FixedUpdate() + { + } +} |