summaryrefslogtreecommitdiff
path: root/ADS.cs
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2024-03-13 11:00:58 +0800
committerchai <215380520@qq.com>2024-03-13 11:00:58 +0800
commit6ce8b9e22fc13be34b442c7b6af48b42cd44275a (patch)
treeb38119d2acf0a982cb67e381f146924b9bfc3b3f /ADS.cs
+init
Diffstat (limited to 'ADS.cs')
-rw-r--r--ADS.cs49
1 files changed, 49 insertions, 0 deletions
diff --git a/ADS.cs b/ADS.cs
new file mode 100644
index 0000000..d20136e
--- /dev/null
+++ b/ADS.cs
@@ -0,0 +1,49 @@
+using System.Collections;
+using UnityEngine;
+
+public class ADS : MonoBehaviour
+{
+ public Vector3 recoilMovement;
+
+ public Vector3 randomRecoilMovement;
+
+ public AnimationCurve curve;
+
+ public float animationSpeed = 1f;
+
+ private Vector3 startPosition;
+
+ private void Start()
+ {
+ startPosition = base.transform.localPosition;
+ }
+
+ private void Update()
+ {
+ }
+
+ public void PlayRecoilAnimation()
+ {
+ StartCoroutine(ApplyRecoil());
+ }
+
+ private IEnumerator ApplyRecoil()
+ {
+ float counter = 0f;
+ float lastValue = curve.Evaluate(0f);
+ float animtionTime = curve.keys[curve.length - 1].time;
+ Vector3 v = recoilMovement + new Vector3(Random.Range(0f - randomRecoilMovement.x, randomRecoilMovement.x), Random.Range(0f - randomRecoilMovement.y, randomRecoilMovement.y), Random.Range(0f - randomRecoilMovement.z, randomRecoilMovement.z));
+ while (counter < animtionTime)
+ {
+ counter += Time.deltaTime * animationSpeed;
+ if (counter > animtionTime)
+ {
+ counter = animtionTime;
+ }
+ float deltaForce = curve.Evaluate(counter) - lastValue;
+ lastValue = curve.Evaluate(counter);
+ base.transform.localPosition += deltaForce * v * 0.001f;
+ yield return null;
+ }
+ }
+}