- Home /
beginner needs AI help
hi i'm making a zombie survival game with health hunger and guns i just have one setback i dont know how to put AI in unity
please help me i need a prefab that works
Unity Gems has some tutorials on how to start writing AI in Unity and has the basic steps creating cover behaviours, path finding etc.
Answer by Lovrenc · Dec 29, 2012 at 09:56 AM
If you have Pro version pathfinding (which i suppose is almost all you need in this game) is easy and you can look it up. If you dont have pro version, you will have to implement algorithm of your choise yourself.
Here is one simple pathfinding algorithm tutorial, it is really simple and well explained and will get you into these waters in soft manner.
And then if results wont suffice you can go further and stop on this awesome site for some A* stuff. A* si very agile algorithm that is (in vanilla version) very easy to implement.
For all custome algorithms you will need to implement some kind of backlogic.
Answer by fafase · Dec 29, 2012 at 11:09 AM
Keep in mind they are zombies, not astrophysicians. The dumber the better.
It is not so easy though, I would think of using the line of sight for basic thing then when losing line of sight, they just continue using the last direction they had before losing sight.
Other need is noise at distance. If you shoot, checking the distance between you and the guy to determine if the zombie heard. Trickier, you can slightly randomize the target position depending on distance so that the further you are, the less accurate their target is. Then they simply start walking towards that point. Should they see you on the way then new target.
Finally, except if you are planning on doing Left For Dead 3, zombies should not use A*. That would mean they are able to think and consider obstacles being between him and the target. They are more likely to bump into obstacles then rotating and continuing.
Consider this situation: You are going around a square building, the zombie follows you, you expect to be able to go around and get the zombie from behind. With A*, the zombie will turn around when you get to the other side as you are closer to reach the other way. Now the zombie is facing you.
I would rather consider breadcrumb algorithm. When your player is spotted, he will start leaving trail of waypoints behind him that the zombie will follow. Those waypoints would disappear after x seconds so that you can evade from him. Then the zombie continues straight ahead totally forgetting he ever chased you.
That was just some little tips.
Your answer
![](https://koobas.hobune.stream/wayback/20220613090056im_/https://answers.unity.com/themes/thub/images/avi.jpg)