I’m working on a 2D platformer, and I’ve run into some issues with setting up an enemy patrol system. It should work as such:
- The enemy should move left and right on a platform. If it reaches one end of the platform, it should stand still for a bit then turn around and travel to the other end.
- If the enemy detects the player, the enemy will travel toward the player. If the player is within a set distance from the enemy’s Line of Sight, the enemy will start to attack the player.
- If the player escapes the enemy’s line of sight, the enemy will continue to move forward for a set amount of time. Once that time has been met, the player will resume patrol.
However, I’ve run into numerous problems with this system, including:
- detecting where the ends of a given platform are
- How to turn the enemy’s line of sight around when it has turned around
- Firing projectiles in the way the enemy is facing
The last one is a particular issue, as I’m not actually rotating the player around; I’m alternating the enemy’s scale on the x-axis, as shown in the Unity 2D tutorial project. If I set a projectile emitter as a child of the enemy object, the emitter’s scale doesn’t change relative to the main object’s scale.
If anyone has any ways to fix this or any of the other issues I’ve highlighted, feel free to respond.