PDA

View Full Version : Guard AI Help



amps7
December 21st, 2005, 10:56 AM
Hi, im no good at AI for a start so please forgive me. I need my enemy guard in this .fla to be able to patrol a small square on the screen and then if the hero comes close within a certain range of this patrolling enemy guard then the enemy guard will chase the hero. And when the enemy guard who is currently folllwing the hero comes close to him he will play his attack animation.

If thats not already difficult then i need to remind you that the enemy needs to be playing the correct animation each time depending on the direction he's facing in. Its basically Zelda style AI for enemys but i have no idea how to do it :pa: .

eiefai
December 21st, 2005, 10:38 PM
hi, maybe this will help you

amps7
December 22nd, 2005, 08:04 AM
Yes thats great the only problem is that firstly i want my enemy to patrol a set area (just a square) and secondly the correct directional animation needs to play because my game is made in a zelda style way where there is four different direction animations.

firehawkdc
December 22nd, 2005, 09:18 AM
Well, the code that eiefai gave was quite well done actually. if you read into it a little more, all you have to do is a little modifications to solve both your problems.

I've modified his code a little and added an 8 directional mc change for both Random Movement and Chase movement.



The Random Movement is quite straight forward.
Chase movement used Angles instead, so you'll need to know which angle the slime is moving before you can assign a directional mc to it.


I've not solved the patrol area for you because it should be simple enough to solve on you own. The idea is to use the same random movement code, but add in a boundary. You'll have to define that boundary on your own though. Where is that square going to be? Is it always the same square?

Or monster cannot move more than 10 or -10 px in x and y axis out of current location. So you get the monster's _x and _y value and experiment from there.

Hope all these help!

This is just the tip of the iceberg. You'll have to master this area first before you can think about creating a RPG, so try solving this code on your own.

Have fun!



Yes thats great the only problem is that firstly i want my enemy to patrol a set area (just a square) and secondly the correct directional animation needs to play because my game is made in a zelda style way where there is four different direction animations.

amps7
December 22nd, 2005, 10:33 AM
Thats Great, thanks alot guys.