summaryrefslogtreecommitdiff
path: root/Thronefall_1_57/Decompile/Thronefall/QuickslingBarrelRotator.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Thronefall_1_57/Decompile/Thronefall/QuickslingBarrelRotator.cs')
-rw-r--r--Thronefall_1_57/Decompile/Thronefall/QuickslingBarrelRotator.cs40
1 files changed, 40 insertions, 0 deletions
diff --git a/Thronefall_1_57/Decompile/Thronefall/QuickslingBarrelRotator.cs b/Thronefall_1_57/Decompile/Thronefall/QuickslingBarrelRotator.cs
new file mode 100644
index 0000000..693df38
--- /dev/null
+++ b/Thronefall_1_57/Decompile/Thronefall/QuickslingBarrelRotator.cs
@@ -0,0 +1,40 @@
+using UnityEngine;
+
+public class QuickslingBarrelRotator : MonoBehaviour
+{
+ public Transform transformToRotate;
+
+ public AutoAttack attack;
+
+ public float attackSmoothTime = 0.05f;
+
+ private Vector3 desiredForward;
+
+ private Vector3 angularVelocityRef;
+
+ private float minSqVelocity = 1.5f;
+
+ private void Start()
+ {
+ if ((bool)attack)
+ {
+ attack.onAttackTriggered.AddListener(OnAttack);
+ }
+ desiredForward = transformToRotate.forward;
+ }
+
+ private void Update()
+ {
+ if (Vector3.Angle(transformToRotate.forward, desiredForward) > 3f)
+ {
+ transformToRotate.forward = Vector3.SmoothDamp(transformToRotate.forward, desiredForward, ref angularVelocityRef, attackSmoothTime);
+ }
+ }
+
+ private void OnAttack()
+ {
+ desiredForward = attack.LastTargetPosition - transformToRotate.position;
+ desiredForward.y = 0f;
+ desiredForward.Normalize();
+ }
+}