summaryrefslogtreecommitdiff
path: root/Assets/Scripts/GamePlay/Player/WheelTransforms.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/Scripts/GamePlay/Player/WheelTransforms.cs')
-rw-r--r--Assets/Scripts/GamePlay/Player/WheelTransforms.cs48
1 files changed, 48 insertions, 0 deletions
diff --git a/Assets/Scripts/GamePlay/Player/WheelTransforms.cs b/Assets/Scripts/GamePlay/Player/WheelTransforms.cs
new file mode 100644
index 0000000..0834f32
--- /dev/null
+++ b/Assets/Scripts/GamePlay/Player/WheelTransforms.cs
@@ -0,0 +1,48 @@
+using System;
+using UnityEngine;
+
+namespace GamePlay.Player
+{
+ [ExecuteAlways]
+ public class WheelTransforms : MonoBehaviour
+ {
+ [Header("Parameters")]
+ [Range(0f, 4f)] public float length;
+ [Range(0f, 4f)] public float width;
+ [Range(-5f, 5f)] public float offsetX;
+ [Range(-5f, 5f)] public float offsetZ;
+ [Range(-5f, 5f)] public float offsetY;
+
+ [Header("Bindings")]
+ public Transform frontLeft;
+ public Transform frontRight;
+ public Transform rearLeft;
+ public Transform rearRight;
+
+#if UNITY_EDITOR
+ private void Update()
+ {
+ if (Application.isPlaying) return;
+ UpdateWheels();
+ }
+#endif
+
+ private void FixedUpdate()
+ {
+ UpdateWheels();
+ }
+
+ private void UpdateWheels()
+ {
+ frontLeft.localPosition = GetPosition(-1, 1);
+ frontRight.localPosition = GetPosition(1, 1);
+ rearLeft.localPosition = GetPosition(-1, -1);
+ rearRight.localPosition = GetPosition(1, -1);
+ }
+
+ private Vector3 GetPosition(float axisX, float axisZ)
+ {
+ return new Vector3(width / 2 * axisX + offsetX, offsetY, length / 2 * axisZ + offsetZ);
+ }
+ }
+}