I am working on a 2D side-scrolling action platformer.
I am currently working on the state logic for my enemies. These are humanoid enemies that walk on the ground
They currently have idle, patrol, chase, engage, and attack states.
The default state is patrol, where they walk back and forth on a platform. If they encounter a wall or cliff, they idle for a few seconds then turn around and patrol in the other direction.
If the player comes within a
chase_radius, they start chasing the player. If the player comes within an
attack_radius, they enter an engaged state where they attack every few seconds.
Currently, I don't have enemies colliding with one another. I allow them to overlap each other. This is nice in the event that two enemies are patrolling in opposite directions. They simply walk passed each other.
The problem is that when two enemies are chasing a player, when one enters the engaged state, they stop and idle until they attack. The second enemy continues to walk until they too are within attack range. They then stop directly on top of the previous enemy and idle until they attack.
In this case, the enemies pretty much completely overlap and it turns an interesting situation with two enemies into a situation with essentially one enemy.
What are some techniques or design choices I can make to prevent this ugly overlap? Ideally, I'd like the enemies to be able to walk passed each other when they are not engaged, but to do something different during combat so that they don't end up overlapping.
I have access to all the normal stuff (for example, raycasting, collision boxes, etc.).
- Enemies overlapping (involves pathfinding, and isn't applicable to 2D sidescroller where enemies walk on ground.)
- How to avoid enemies overlapping each other when chasing player in Unity? (solution of gradually pulling enemies apart when they overlap won't look natural with humanoid enemies that do melee attacks).