• Advertisement
Sign in to follow this  

Simple AI

This topic is 3424 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am making a 2D action style RPG and I want the enemies to attack the player, not just run around in random movements. I can wrote something to get them to run randomly. My question is how would I make them appear to see the player and then chase after him? Kind of like Zelda: A Link to the Past.

Share this post


Link to post
Share on other sites
Advertisement
The AI has a few states: standing, attacking, chasing, returning.

When the unit is standing, every so often, have it check for a nearby target. If it has one, it goes into chasing mode. If the target is out of the unit's range, it moves towards it. When the target is in range, the mode switches to attacking and the unit fires its weapon or attacks. If the target goes out of range, the unit goes back into chasing mode. If the unit strays too far from it's original location, it goes into returning mode, where it moves towards its original guard spot. Once it reaches that spot, it returns to standing mode.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement