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.

You’ll need a couple things.

  1. 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”.
  2. You’ll need to build a function (that probably spawns a coroutine) that allows you to say in 1 call MoveTo(position).
  3. 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.

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!

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