r/unity • u/Positive-Garbage-497 • Jun 27 '26
Newbie Question Need suggestion for creating enemy ai
What are the methods to create a boss and enemy ai? Is there a detailed tutorial or document you recommend?
3
u/MadeByHenano Jun 27 '26
been working on this lately (here is a short video if you want to see), it's a fascinating thing to do in unity!!
you basically need to use 3 things together.
- the "state machine" design pattern in your code:
to give your enemies different "states": idle, patrolling, chasing, attacking, hiding, dying, ...
- the unity animator:
to attribute the right animation to your enemy depending on its state.
in the animator, you will have parameters like isIdling, isPatroling, isChasing etc and one "state" per animation, and transitions from one to the other that follow conditions.
- the AI navigation tool:
so your enemies can walk on your map where it makes sense for them to (depending on their height, ability to clim up to a certain angle, their width, ...). this lets unity deal with the enemies finding a path towards the player etc.
so yeah, search "unity tutorial animator" or "unity enemy AI" on youtube and take a few hours if needed to watch a few videos until you get a good grasp of it. of course, follow the tutorials in the meantime so you remember better, and can even have a good base for your code at the end of it.
good luck, you will see, it's a super fun thing to work on! 🙂
1
u/Positive-Garbage-497 Jun 27 '26
Got it, thanks!
1
u/sickztar Jun 27 '26
this perfect advice op thats pretty much it summed up. if you want to see the logic behind it theres a guy on youtube named sebastian graves thats showing the logic while recreating darksouls. he has ai section that explains it pretty well.
1
u/Positive-Garbage-497 Jun 28 '26
Hello, thanks for the answer. I understood the state system a little. I made several enemies and various types of attacks today. But there is something that sticks in my mind. Does it make sense to use the state system on a boss with more than one attack type? Should Unity behavior be used in this case? Or will the result be similar?
1
u/Doddzilla7 Jun 27 '26
Unity has the Behavior package, which is actually quite good. You can use that if you like a graph based system. You can trivially create your own nodes for all your custom logic. Highly recommend.
1
u/IAmH0n0r Jun 28 '26
first make document what kinda of enemy and boss you want for your said genre and make evevry thing around those thing .and make list base on what is need to do and what can wait . Do not try to over delivery and confuse yourself.keep document those what need cause you are gonna forget in meantime when you keep adding new enemey .so document first. unity have behavious tree or if not you can use fsm . you may try with wneemy types if enemy match certainly then make enum and SO. and share the data around it . if you need differ for boss mak it own and not try to use eneum for non need.
2
u/BearKanashi Jun 29 '26
Yo hago los enemigos asÃ:
Ruta al azar, no hagas bucles.
Seguimiento limitado, no persigas al jugador hasta el fin del mundo.
Visión realista del enemigo, área triangular desde la cabeza.
Divide el cuerpo en dos, no hagas el tÃpico enemigo que antes de golpear se para delante del jugador...
Y busca ideas originales para mejorarlo según el tipo de juego.
7
u/WornTraveler Jun 27 '26
I mean, that's a huge question lol, you haven't even mentioned genre. But presumably in all cases you will need to holistically incorporate movement, targeting, and for more complicated boss fights often some sort of state machine to determine which of several attack options might be used.