Let down by my enemies

Blitz3D Forums/Blitz3D Programming/Let down by my enemies

cash(Posted 2007) [#1]
I know there are hundreds of posts relating to enemies and AI etc but I am still frustrated by my enemies..

Does anyone have any simple code which allows simple enemy handling, I seem to end up with tons of switches to change the animation state etc and I am sure there must be a simpler way.
The enemies in my game are more of a nuisance for the player than game necessity, hence I dont need really complex AI.

I have some .b3d enemies with several animation sequences assigned. This is all good but things like idle, following the player, attacking and running away become a jumble. (For me anyway).
Any help appreciated.


Vertigo(Posted 2007) [#2]
I would suggest having a state machine. And flag your enemy types with an AI_STATE% field. This can contain IDLE SEARCHING ATTACKING FLEEING whatever you want. Run checks against the ai's current position relative to the player, if its within its sight range, then change the state to searching or chasing and this would change the animation type to walk/run whatever. Next if the ai_state is searching and the player is within weapon range change the state to attacking. If the state is attacking and the player falls out of range, go back to chasing... if the player is out of search range while chasing go back to idle. Its really dumb ai, but it should work for what you are wanting.


Hujiklo(Posted 2007) [#3]
For my simple A.I enemies I eventually realised it was best to set the priority for each of the states. The ultimate and un-overridable state was the death sequence, then the recoil or falling of a ledge, then attacking, then the sort of neutral stuff could mix and match as it wished. I hope you understand this...basically I think switches/states is fine...just get them in order and check if they have permission to execute their particlar sections of behaviour code - A hierarchy of sorts.


Gillissie(Posted 2007) [#4]
To add to Hujiklo's priority-based idea, you can have a list of actions that an enemy wants to do. The list should be sorted in priority. This way, after the highest priority item is done, it automatically reverts back to what it was doing before it was interrupted. Of course, if it dies or something along the way, then the list of priorities should be deleted along with the character, so it will automatically cancel all other priorities instead of trying to revert back to patrolling after dying (for example).


cash(Posted 2007) [#5]
Thanks for the tips. I will go and test them out. Probably best to draw it out first.