[DEMO] Enemy A.I. - State Machine
- MJ Lindsay

- Mar 8, 2022
- 1 min read
Updated: Apr 5, 2022

This enemy can Patrol, Chase, Search, Attack, Listen, Retreat.
Enemy eyeslight is done using raycasting. Walking within the orange area will not alert the enemy, unless the player is running. If the player walks within the red area the enemy will hear them regardless of speed.
Patrolling - The enemy will move from one set patrol point to the next before returning to the first. By using an expandable array, as many patrol points as you want or need can be added.
Listening - If the player speed is above regular walking speed while within the listening area (orange) the enemy will turn towards the noise, being able to find the player.
Chasing - If the player is spoted by the enemy raycast, the enemy will chase after the player as quick as it can
Searching - If the player manages to get away, the enemy will stop and search the last known spot the player was in. If the player re-emerges the enemy will return to chasing.
Retreating - If the enemy is unsucessful in searching for the missing player, the enemy will retreat back to its starting patrol point.
Made in Unity, 2021;
Try out the demo for yourself: CLICK HERE
Check out the code on GitHub: CLICK HERE

![[Involvement] Tiny FPS (WIP)](https://static.wixstatic.com/media/0af790_46166da05d3749ab90c66bb281e724c1~mv2.png/v1/fill/w_962,h_541,al_c,q_90,enc_avif,quality_auto/0af790_46166da05d3749ab90c66bb281e724c1~mv2.png)
![[WIP] Shoot'em Up](https://static.wixstatic.com/media/0af790_129c46a0f11945fbbe65ac66419219b7~mv2.jpg/v1/fill/w_741,h_385,al_c,q_80,enc_avif,quality_auto/0af790_129c46a0f11945fbbe65ac66419219b7~mv2.jpg)
![[DEMO] UI Types](https://static.wixstatic.com/media/0af790_d6e91a5761ee4b3699dfad7e18a63eac~mv2.png/v1/fill/w_980,h_552,al_c,q_90,usm_0.66_1.00_0.01,enc_avif,quality_auto/0af790_d6e91a5761ee4b3699dfad7e18a63eac~mv2.png)
Comments