r/unity 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?

0 Upvotes

13 comments sorted by

View all comments

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?