Browse Source

风筝忍者靠近玩家会逃跑.

1243896040 1 week ago
parent
commit
08cefe470e

+ 2 - 0
ActionTowerDefense/Assets/Resources/Prefab/ESpirits/ESpirits_KiteNinja.prefab

@@ -1718,6 +1718,8 @@ MonoBehaviour:
   lockingLogic: {x: 1, y: 2}
   revivesNum: 2
   revivesPos: {x: 10, y: 3}
+  fleeDistance: 10
+  fleeSpeedRate: 1
   targetIsPlayer: 0
   lockingNum: 0
   lockCharacter: {fileID: 0}

+ 29 - 0
ActionTowerDefense/Assets/Scripts/Spirits/ESpirits_KiteNinja.cs

@@ -11,6 +11,8 @@ public class ESpirits_KiteNinja : Enemy
     [LabelText("锁敌逻辑")] public Vector2 lockingLogic;
     [LabelText("复活次数")] public int revivesNum;
     [LabelText("复活范围")] public Vector2 revivesPos;
+    [LabelText("逃跑距离")] public float fleeDistance;
+    [LabelText("逃跑速度比例")] public float fleeSpeedRate;
     public bool targetIsPlayer;
     public int lockingNum;
     private PlayerController player;
@@ -43,6 +45,33 @@ public class ESpirits_KiteNinja : Enemy
                         0);
                 }
                 return;
+            case CharacterState.Attack:
+                float distance = player.transform.position.x - transform.position.x;
+                if (distance > 0.3f)
+                {
+                    if (bodyTrans.localScale.x > 0)
+                    {
+                        Turn();
+                    }
+                }
+                else if (distance < -0.3f)
+                {
+                    if (bodyTrans.localScale.x < 0)
+                    {
+                        Turn();
+                    }
+                }
+                if (Mathf.Abs(distance) < fleeDistance)
+                {
+                    Vector3 velocity = Vector3.right * moveSpeed * fleeSpeedRate;
+                    if (distance > 0)
+                    {
+                        velocity.x = -velocity.x;
+                    }
+                    rb.velocity = velocity * moveSpeedScale;
+                }
+                
+                break;
         }
         base.OnState();
     }