diff --git a/Assets/Gameplay/Virus.cs b/Assets/Gameplay/Virus.cs index a8295ea..5695cdf 100644 --- a/Assets/Gameplay/Virus.cs +++ b/Assets/Gameplay/Virus.cs @@ -38,6 +38,8 @@ private SimpleTween attackTween; private SimpleTimer attackTimer; + private bool lastPathFailed = true; + private void PathToPlayer() { List players = new List(); @@ -53,9 +55,25 @@ if (players.Count == 0) { + if (lastPathFailed) + { + targetPlayer = null; + nav.stoppingDistance = AttackMaxDist * 0.8f; + nav.isStopped = false; + + Vector2 r = UnityEngine.Random.insideUnitSphere * 4; + nav.destination = new Vector3(r.x, transform.position.y, r.y); + + return; + } repathTimer.Start(3, PathToPlayer); + lastPathFailed = true; + return; } + lastPathFailed = false; + + float total = weights.Sum(); targetPlayer = null; @@ -83,6 +101,7 @@ public void StopPathing() { + lastPathFailed = false; nav.isStopped = true; } @@ -131,7 +150,7 @@ { if (IsPathFinished()) { - if (DistToTarget > AttackMaxDist) + if (targetPlayer != null && DistToTarget > AttackMaxDist) { nav.destination = TargetBasePos; } @@ -141,16 +160,22 @@ AttackTarget(); } } - else if (targetPlayer == null) + else if (targetPlayer == null && !lastPathFailed) { StopPathing(); targetPlayer = null; PathToPlayer(); } - else if (Time.realtimeSinceStartup > pathTime + RepathTime && DistToTarget > 2) + else if (!lastPathFailed && Time.realtimeSinceStartup > pathTime + RepathTime && DistToTarget > 2) { nav.destination = TargetBasePos; } + else if (lastPathFailed && Time.realtimeSinceStartup > pathTime + 10) + { + StopPathing(); + targetPlayer = null; + PathToPlayer(); + } } }