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 --- AddCameraMovementByRig.cs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 AddCameraMovementByRig.cs (limited to 'AddCameraMovementByRig.cs') diff --git a/AddCameraMovementByRig.cs b/AddCameraMovementByRig.cs new file mode 100644 index 0000000..905b69a --- /dev/null +++ b/AddCameraMovementByRig.cs @@ -0,0 +1,31 @@ +using UnityEngine; + +public class AddCameraMovementByRig : MonoBehaviour +{ + public Rigidbody rig; + + public float movementMultiplier = 1f; + + public float returnForce; + + public float rigForce; + + public float friction = 0.97f; + + private Vector3 velocity; + + private Vector3 startPos; + + private void Start() + { + startPos = base.transform.localPosition; + } + + private void FixedUpdate() + { + velocity -= rig.velocity * rigForce; + velocity += (base.transform.parent.TransformPoint(startPos) - base.transform.position) * returnForce; + velocity *= friction; + base.transform.position += velocity * movementMultiplier; + } +} -- cgit v1.1-26-g67d0