yichael vor 4 Jahren
Ursprung
Commit
56833a6083
1 geänderte Dateien mit 24 neuen und 0 gelöschten Zeilen
  1. 24 0
      Assets/BowArrow/Scripts/Game/ArmBow.cs

+ 24 - 0
Assets/BowArrow/Scripts/Game/ArmBow.cs

@@ -9,6 +9,9 @@ public class ArmBow : MonoBehaviour
     [SerializeField] GameObject arrow;
     [SerializeField] BowCamera bowCamera;
     public HashSet<TargetBody> validTargets = new HashSet<TargetBody>();
+
+    public int shootBackTime = 0;
+
     private bool canShoot = false;
     private bool pulling = false;
     private bool readying = false;
@@ -120,6 +123,27 @@ public class ArmBow : MonoBehaviour
 
         // 筛选出一个稳定的发射角度---start
         Quaternion best_rotation = this.bowCamera.transform.rotation;
+        if (recordCount >= recordRotations.Length) {
+            int single_check_count = 6;
+            float min_wave = float.MaxValue;
+            for (int i = 0; i < recordRotationVars.Length; i++)
+            {
+                recordRotationVars[i] = Quaternion.Angle(recordRotations[i], recordRotations[i + 1]);
+                if (i >= single_check_count - 1) 
+                {
+                    float wave = 0;
+                    for (int j = i; j > i - single_check_count; j--)
+                    {
+                        wave += recordRotationVars[j];
+                    }
+                    if (wave < min_wave)
+                    {
+                        min_wave = wave;
+                        best_rotation = recordRotations[i - single_check_count + 1-this.shootBackTime];
+                    }
+                }
+            }
+        }
         // if (recordCount >= recordRotations.Length) {
         //     int single_check_count = 6;
         //     float min_wave = float.MaxValue;