Browse Source

偏移角算法调整

lvjincheng 4 năm trước cách đây
mục cha
commit
ecab889adb

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

@@ -218,6 +218,7 @@ public class ArmBow : MonoBehaviour
         arrowComp.offsetAngle = GameDebug.ins ? 
             GameDebug.ins.GetOffsetAngle() : 
             FormatAngle(Quaternion.Angle(absolute_rotation, final_rotation));
+        arrowComp.finalAngleAfterOffset = final_rotation.eulerAngles;
 
         if (ShootCheck.ins && !GameMgr.debugInEditor && !BowCamera.isTouchMode) 
         {

+ 15 - 2
Assets/BowArrow/Scripts/Game/Arrow.cs

@@ -23,6 +23,8 @@ public class Arrow : MonoBehaviour
         [NonSerialized] public RaycastHit absoluteRay;
         //制作误差偏移角(强行制造误差,为了增加游戏难度,该偏移角的大小根据难度而定)
         [NonSerialized] public float offsetAngle;
+        //误差偏移后的欧拉角
+        [NonSerialized] public Vector3 finalAngleAfterOffset;
     #endregion
 
     //射线击中的靶子
@@ -86,8 +88,12 @@ public class Arrow : MonoBehaviour
         float maxDeltaAngleX = 5;
         //最终角
         float finalAngleX = baseAngleX;
+        //额外偏移误差角
+        float offsetAngleX = FormatAngleX(this.finalAngleAfterOffset.x) - baseAngleX;
+        float offsetAngleY = this.finalAngleAfterOffset.y - this.transform.eulerAngles.y;
 
         if (absoluteRay.transform) {
+            bool plusOffsetAngleY = false;
             //看能否通过调整发射角让箭落在靶子的瞄准点上
             CalculateParabolaAngle(absoluteRay.point); 
             //瞄准的是不是Target层
@@ -103,7 +109,8 @@ public class Arrow : MonoBehaviour
                 
                 //如果绝对角跟原本角度相差不超过maxDeltaAngleX
                 if (Mathf.Abs(deltaAngleX) < maxDeltaAngleX) {
-                    finalAngleX = Mathf.Clamp(absoluteAngleX + offsetAngle, -89, 89);
+                    finalAngleX = Mathf.Clamp(absoluteAngleX + offsetAngleX, -89, 89);
+                    plusOffsetAngleY = true;
                     if (Math.Abs(offsetAngle) < 0.01) {
                         canPerfectHit = true;
                     }
@@ -111,11 +118,17 @@ public class Arrow : MonoBehaviour
                         canUseSideCamera = true;
                     }
                 } else {
-                    finalAngleX = Mathf.Clamp(baseAngleX + maxDeltaAngleX + this.offsetAngle, -89, 89);
+                    finalAngleX = Mathf.Clamp(baseAngleX + maxDeltaAngleX, -89, 89);
                     if (isTargetLayer) AimLoadChecker.ins?.ShowOutTip();
                 }
             }
             finalPoint = absoluteRay.point;
+            if (plusOffsetAngleY) {
+                Vector3 myPos = this.transform.position;
+                Vector3 pointer = finalPoint - myPos;
+                pointer = Quaternion.AngleAxis(offsetAngleY, Vector3.up) * pointer;
+                finalPoint = myPos + pointer;
+            }
         } else {
             finalPoint = this.transform.position + this.transform.forward * 100;
         }