瀏覽代碼

风筝忍者逃跑向上逃

1243896040 1 周之前
父節點
當前提交
8546019215

+ 1 - 1
ActionTowerDefense/Assets/Resources/Prefab/ESpirits/ESpirits_KiteNinja.prefab

@@ -1719,7 +1719,7 @@ MonoBehaviour:
   revivesNum: 2
   revivesPos: {x: 10, y: 3}
   fleeDistance: 10
-  fleeSpeedRate: 1
+  fleeSpeedRate: {x: 0.8, y: 0.2}
   targetIsPlayer: 0
   lockingNum: 0
   lockCharacter: {fileID: 0}

+ 17 - 4
ActionTowerDefense/Assets/Scripts/Spirits/ESpirits_KiteNinja.cs

@@ -12,7 +12,7 @@ public class ESpirits_KiteNinja : Enemy
     [LabelText("复活次数")] public int revivesNum;
     [LabelText("复活范围")] public Vector2 revivesPos;
     [LabelText("逃跑距离")] public float fleeDistance;
-    [LabelText("逃跑速度比例")] public float fleeSpeedRate;
+    [LabelText("逃跑速度比例")] public Vector2 fleeSpeedRate;
     public bool targetIsPlayer;
     public int lockingNum;
     private PlayerController player;
@@ -20,6 +20,7 @@ public class ESpirits_KiteNinja : Enemy
     public override void Init()
     {
         base.Init();
+        rb.constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotation;
         targetIsPlayer = true;
         lockingNum = 0;
         player = PlayersInput.instance[0];
@@ -61,16 +62,28 @@ public class ESpirits_KiteNinja : Enemy
                         Turn();
                     }
                 }
+                Vector3 velocity = rb.velocity;
                 if (Mathf.Abs(distance) < fleeDistance)
                 {
-                    Vector3 velocity = Vector3.right * moveSpeed * fleeSpeedRate;
+                    velocity = new Vector3(moveSpeed * fleeSpeedRate.x,moveSpeed * fleeSpeedRate.y,0);
                     if (distance > 0)
                     {
                         velocity.x = -velocity.x;
                     }
-                    rb.velocity = velocity * moveSpeedScale;
+
+                }
+                else
+                {
+                    if(transform.position.y > flyHeight)
+                    {
+                        velocity.y = moveSpeed * fleeSpeedRate.y;
+                    }
+                    else
+                    {
+                        velocity.y = 0;
+                    }
                 }
-                
+                rb.velocity = velocity * moveSpeedScale;
                 break;
         }
         base.OnState();