From 6ce8b9e22fc13be34b442c7b6af48b42cd44275a Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Wed, 13 Mar 2024 11:00:58 +0800 Subject: +init --- FPSCarCam.cs | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 FPSCarCam.cs (limited to 'FPSCarCam.cs') 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(); + } + + 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() + { + } +} -- cgit v1.1-26-g67d0