- Home /
How to get zombie AI working
Hello, I would like to know what you have to do from start to finish with Zombie ai.
I just want the zombie to come after me and attack me and be able to get killed by me shooting at it.
Thanks for looking any help would be really appreciated. Anything like tutorials or just personal advise.
Answer by Mortoc · Jul 10, 2012 at 01:48 PM
You'll need a couple things.
An efficient way to detect proximity. Physics.OverlapSphere or just colliders set as triggers are good for this. This is so you can say, "Enemy is close to player, do something now".
You'll need to build a function (that probably spawns a coroutine) that allows you to say in 1 call MoveTo(position).
All your animations and things should be driven from these "events". Example: by default play idle, when the event "Player comes close" happens, you play your "alarmed and smells brains" animation then when you start walking towards the player, you play the walk animation.
You don't really need an AI tutorial to write AI, it's actually not very complicated. You do need to have a good handle on scripting in Unity, so following any of the getting started tutorials is a good way to start.
Answer by captaincrunch80 · Jul 10, 2012 at 01:57 PM
Well that sounds like a seek or arrive behavior paired with some attack animations when in range. But most likely you later want the zombie to avoid walls etc. so you need pathfinding too.
I recommend the Book "Artificial Intelligence for games" from Ian Millington. The basic stuff you want is not hard to implement. It's Chapter 3.2 and 3.3
Shooting at in the most basic form, can be implemented with raycasting. If you play with the FPS controller, you could do a ScreenPointToRay form your crosshair position and then Raycast with that. If you hit the zombie, subtract some of it's health.
Good hunt!
Answer by gochi7 · Apr 18, 2013 at 06:40 PM
I would have the zombie walking to random points on a navmesh (I use xaitment) and use raycasting for the zombie to detect if you are in front of it by setting it to check if what it's hitting is "player" or not, if it's "player" then run towards it and attack, you'll need to set the movement to stop once the health hits 0 of course. that's the easiest way I can think of to do it, hope this helps, feel free to ask me if you have any trouble with this
Your answer

Follow this Question
Related Questions
How to detect if something is added to PlayerPrefs? 2 Answers
activating a Camera Using a Toggle Button 1 Answer
How to Repeating command in js 3 Answers
How to swap weapons easily? 1 Answer