Ver Fonte

射箭功能优化

lvjincheng há 4 anos atrás
pai
commit
ffb367212d

+ 0 - 6
Assets/BowArrow/Scripts/Game/AimLoadChecker.cs

@@ -8,12 +8,6 @@ public class AimLoadChecker : MonoBehaviour
 {
 {
     [SerializeField] GameObject outTip;
     [SerializeField] GameObject outTip;
 
 
-    void Start()
-    {
-        
-    }
-
-    // Update is called once per frame
     void Update()
     void Update()
     {
     {
         bool needActiveOutTip = false;
         bool needActiveOutTip = false;

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

@@ -171,7 +171,7 @@ public class ArmBow : MonoBehaviour
         arrowComp.absoluteRay = absoluteRay;
         arrowComp.absoluteRay = absoluteRay;
         arrowComp.offsetAngle = GameDebug.ins ? 
         arrowComp.offsetAngle = GameDebug.ins ? 
             GameDebug.ins.GetOffsetAngle() : 
             GameDebug.ins.GetOffsetAngle() : 
-            Vector3.Angle(absolute_rotation.eulerAngles, final_rotation.eulerAngles);
+            FormatAngle(final_rotation.eulerAngles.x) - FormatAngle(absolute_rotation.eulerAngles.x);
 
 
         if (ShootCheck.ins && !GameMgr.debugInEditor) 
         if (ShootCheck.ins && !GameMgr.debugInEditor) 
         {
         {
@@ -185,6 +185,13 @@ public class ArmBow : MonoBehaviour
         // this.gameObject.SetActive(false);
         // this.gameObject.SetActive(false);
     }
     }
 
 
+    float FormatAngle(float value)
+    {
+        if (value > 180) value = 360 - value;
+        else value = -value;
+        return value;
+    }
+
     public void OnEnable() 
     public void OnEnable() 
     {
     {
         AudioMgr.GetAudioSource(this.gameObject).clip = null;
         AudioMgr.GetAudioSource(this.gameObject).clip = null;

+ 20 - 9
Assets/BowArrow/Scripts/Game/Arrow.cs

@@ -61,26 +61,37 @@ public class Arrow : MonoBehaviour
     {
     {
         CalculateParabolaAngle(absoluteRay.point); 
         CalculateParabolaAngle(absoluteRay.point); 
 
 
-        float maxAngleX = 5;
         if (!hasParabolaAngle) return;
         if (!hasParabolaAngle) return;
+
+        float baseAngleX = this.transform.eulerAngles.x;
+        if (baseAngleX > 180) baseAngleX = baseAngleX - 360;
+        baseAngleX *= -1;
+
         float absoluteAngleX = parabolaAngleInRadian / Mathf.PI * 180;
         float absoluteAngleX = parabolaAngleInRadian / Mathf.PI * 180;
-        if (absoluteAngleX > maxAngleX) {
-            absoluteAngleX = maxAngleX;
+
+        float deltaAngleX = absoluteAngleX - baseAngleX;
+        float maxDeltaAngleX = 5;
+
+        float finalAngleX = this.offsetAngle;
+        if (Mathf.Abs(deltaAngleX) > maxDeltaAngleX) {
+            finalAngleX += baseAngleX;
+            finalAngleX += deltaAngleX > 0 ? maxDeltaAngleX : -maxDeltaAngleX;
+        } else {
+            finalAngleX += absoluteAngleX;
         }
         }
-        float finalAngleX = absoluteAngleX + this.offsetAngle;
+
         float vy = Mathf.Sin(finalAngleX / 180 * Mathf.PI) * this.mySpeed;
         float vy = Mathf.Sin(finalAngleX / 180 * Mathf.PI) * this.mySpeed;
         float vx = Mathf.Cos(finalAngleX / 180 * Mathf.PI) * this.mySpeed;
         float vx = Mathf.Cos(finalAngleX / 180 * Mathf.PI) * this.mySpeed;
         float deltaX = Mathf.Sqrt(
         float deltaX = Mathf.Sqrt(
             Mathf.Pow(absoluteRay.point.x - this.shootOutPosition.x, 2) + 
             Mathf.Pow(absoluteRay.point.x - this.shootOutPosition.x, 2) + 
             Mathf.Pow(absoluteRay.point.z - this.shootOutPosition.z, 2)
             Mathf.Pow(absoluteRay.point.z - this.shootOutPosition.z, 2)
         );
         );
-        float deltaY = absoluteRay.point.y - this.shootOutPosition.y;
         float tx = deltaX / vx;
         float tx = deltaX / vx;
-        float finalDeltaY = vy * tx + 0.5f * Physics.gravity.y * tx * tx;
-        float dy = finalDeltaY - deltaY;
-        if (Mathf.Abs(dy) < 0.62f) { //靶子范围内,则用update运算物理
+        float dy = vy * tx + 0.5f * Physics.gravity.y * tx * tx;
+
+        if (Mathf.Abs(dy) < 0.62f) { //靶子范围内,则用update运算物理
             finalPoint = absoluteRay.point;
             finalPoint = absoluteRay.point;
-            finalPoint.y += dy;
+            finalPoint.y = absoluteRay.transform.parent.position.y + dy;
             useUpdatePhysics = true;
             useUpdatePhysics = true;
             parabolaAngleInRadian = finalAngleX / 180 * Mathf.PI;
             parabolaAngleInRadian = finalAngleX / 180 * Mathf.PI;
             RandomUseSideCamera();
             RandomUseSideCamera();