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 --- WheelVisualizer.cs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 WheelVisualizer.cs (limited to 'WheelVisualizer.cs') diff --git a/WheelVisualizer.cs b/WheelVisualizer.cs new file mode 100644 index 0000000..679db09 --- /dev/null +++ b/WheelVisualizer.cs @@ -0,0 +1,37 @@ +using UnityEngine; + +public class WheelVisualizer : MonoBehaviour +{ + private Rigidbody rig; + + public float spinAmount; + + public float inputVelocityAmount; + + public float inputReturnVelocityAmount; + + public float inputFriction; + + private GenericInputHandler input; + + private float inputVelocity; + + private void Start() + { + rig = GetComponentInParent(); + input = GetComponentInParent(); + } + + private void FixedUpdate() + { + inputVelocity *= inputFriction; + } + + private void Update() + { + inputVelocity += input.inputDirection.x; + inputVelocity -= inputVelocity * inputReturnVelocityAmount * Time.deltaTime; + base.transform.localRotation = Quaternion.Euler(0f, inputVelocity * inputVelocityAmount, 0f); + base.transform.GetChild(0).Rotate(Vector3.right * spinAmount * Time.deltaTime * rig.transform.InverseTransformDirection(rig.velocity).z, Space.Self); + } +} -- cgit v1.1-26-g67d0