diff options
author | chai <215380520@qq.com> | 2024-03-13 11:00:58 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2024-03-13 11:00:58 +0800 |
commit | 6ce8b9e22fc13be34b442c7b6af48b42cd44275a (patch) | |
tree | b38119d2acf0a982cb67e381f146924b9bfc3b3f /FPSCarCam.cs |
+init
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() + { + } +} |