Search Unity

Enemy AI questions

Discussion in 'Scripting' started by HarleyK, Jul 13, 2017.

  1. HarleyK

    HarleyK

    Joined:
    Mar 27, 2015
    Posts:
    95
    So I was viewing the finite AI state machine that uses the delegate system for actions and states, and I was wondering if this would be the best route for the type of game. I am currently using a procedural generated terrain that creates a new map every time the map is loaded, this is also a fps. I basically have normal zombie enemies I want to create that wander and or patrol but chase the player and attack when they get close but also continue to patrol if the player is too far out of sight. However the issue is making the zombies follow a set of transforms, because i don't know if i should already set transforms for all zombies to follow at random or if i can procedural generate points at random for the zombies to follow. Any thoughts on the matter or advice is highly appreciated.
     
  2. HarleyK

    HarleyK

    Joined:
    Mar 27, 2015
    Posts:
    95
  3. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,697
    Before I offer my advice, let me preface it by saying that I am a strong believer in "simpler is better," and with FPS AI "the simplest is often plenty enough."

    First off, I would not bother with transform waypoints... yet.

    Zombie version 0.1 I would give the following properties:

    - select a short distance and walk that distance, UNLESS:
    ---- you spot the player, at which point, run to the player
    ---- if the player gets too far, then give up and wander
    - if you collide with something, turn to a new direction and reset your wandering
    - when you have wandered that distance, turn a little bit (not much) and wander more
    ---- you can also put in a pensive moment here, like, pause dramatically while turning

    You could probably stick all that in a single coroutine, like IEnumerator Start() even.

    If you have a separate coroutine that only checks every few seconds for the player, and perhaps only looks in a few random radius points in a straight line ahead of the zombie, then you can actually get the effect of being able to sprint across a zombie's line of sight and have him not "catch" you.

    Zombie version 0.2 might look for other zombies as well as the player:

    - if he finds a zombie he will tend to go stand near them and mumble, or mill around near that zombie
    ---- have a timer that cools off this behavior after a while, so he loses interest in his buddy and begins to patrol again

    The 0.2 feature might cause some interesting clumping, and it might be degenerate if you make the odds of going to other zombies too high, so put in ways to tune the odds of each of these things happening.

    Zombie 0.3 might give a shriek when he sees the player, and nearby zombies hear it and suddenly are given the player's location, and if it is close enough, they join in the chase. That could cause some interesting things to happen...

    In general, looking above I see some tunable properties you want to expose and probably be able to grossly vary on your zombie crowd:
    - how often they look for the player
    - how fast they go
    - how far they wander before turning
    - how long they might pause and think
    - chance of going towards a spotted fellow zombie
    - time to hang out with his buddy
    - radius of shriek alert

    Hope that gets you thinking... I'd try out just 0.1 first, see what it gets you.

    The coolest part about this sort of AI is the first time it comes to life you will have a MASSIVE grin on your face, kinda like a proud father, and you will immediately want to show all your friends what you did.
     
    HarleyK likes this.
  4. HarleyK

    HarleyK

    Joined:
    Mar 27, 2015
    Posts:
    95
    Thank you for the insight on this, I agree with the simple is better strategy because a lot of times I tend to over think the issues at hand. I will def. try out some of the ideas you mentioned above, the team I'm working with wants me to start with a simple zombie then work on some zombies that can operate guns and a few zombie animals, which I'm excited to do the AI for them but i got kinda overwhelmed on the best ways of going about it because I've never done AI a whole bunch before.