diff --git a/Assets/Prefabs/Fighters/AntiPlayer.prefab b/Assets/Prefabs/Fighters/AntiPlayer.prefab index bf82cdb8fe065de1c87267e1027a2e79f217772f..09a890486c4b0dacb92b4b0e701e69add521dc41 100644 --- a/Assets/Prefabs/Fighters/AntiPlayer.prefab +++ b/Assets/Prefabs/Fighters/AntiPlayer.prefab @@ -116,6 +116,7 @@ MonoBehaviour: currentHealth: 100 maxDistanceToEnemy: 1 movementSpeed: 4 + delayUntilNextTarget: 0.3 --- !u!95 &2655505060201611074 Animator: serializedVersion: 3 diff --git a/Assets/Scripts/Fighters/AntiPlayer.cs b/Assets/Scripts/Fighters/AntiPlayer.cs index 351e2a20397ef94a091128872fbb4303d52f9203..5c43430ad91e8243daf4193bb887d71306a5beb6 100644 --- a/Assets/Scripts/Fighters/AntiPlayer.cs +++ b/Assets/Scripts/Fighters/AntiPlayer.cs @@ -8,6 +8,8 @@ public class AntiPlayer : Fighter, IFighterCallback [SerializeField, Tooltip("How close the AntiPlayer has to be to start attacking, or how far away it has to be to start running towards the target")] float maxDistanceToEnemy = 1f; [SerializeField] float movementSpeed = 4f; + [SerializeField, Tooltip("After killing an Enemy, how long to stay idle before targeting the next enemy")] + float delayUntilNextTarget = 0.3f; List<Fighter> enemies = new List<Fighter>(); Fighter currentTargetEnemy; @@ -81,6 +83,9 @@ public class AntiPlayer : Fighter, IFighterCallback public void OnFighterDeath(Fighter fighter) { enemies.Remove(fighter); - CalculateClosestEnemy(); + // Wait a short time before targeting next enemy. This is to avoid interrupting the current + // attack animation, which would happen if we immediately ran to the next target. + currentTargetEnemy = null; + Invoke(nameof(CalculateClosestEnemy), delayUntilNextTarget); } } diff --git a/Assets/Scripts/Fighters/Fighter.cs b/Assets/Scripts/Fighters/Fighter.cs index f347de9741a2d16497cbffa4dec7a55b4f4df081..acd9fcb37726a0e6ffad28672026ff3845c11460 100644 --- a/Assets/Scripts/Fighters/Fighter.cs +++ b/Assets/Scripts/Fighters/Fighter.cs @@ -22,7 +22,7 @@ public abstract class Fighter : MonoBehaviour [SerializeField] protected int currentHealth = 100; protected Animator animator; protected new Rigidbody2D rigidbody; - protected SpriteRenderer spriteRenderer; + protected BoxCollider2D collider; protected bool alive { get => currentHealth > 0; } protected FighterTypes fighterType; protected string opponentTag; @@ -39,7 +39,7 @@ public abstract class Fighter : MonoBehaviour { animator = GetComponent<Animator>(); rigidbody = GetComponent<Rigidbody2D>(); - spriteRenderer = GetComponent<SpriteRenderer>(); + collider = GetComponent<BoxCollider2D>(); fighterType = FighterTypes.ENEMY; initalPosition = transform.position; initalScale = transform.localScale; @@ -83,6 +83,10 @@ public abstract class Fighter : MonoBehaviour { animator.SetTrigger("Death"); callbacks.ForEach(c => c.OnFighterDeath(this)); + // Disable own collider so that other Fighters can run over our dead body + collider.enabled = false; + // Let's not fall through the world, without any active colliders + rigidbody.bodyType = RigidbodyType2D.Static; } else {