Sign in to follow this  
Zkd

Simple AI

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this