Search Unity

AI dodging behaviour in Unity

Discussion in 'Scripting' started by Lethn, Aug 30, 2017.

  1. Lethn

    Lethn

    Joined:
    May 18, 2015
    Posts:
    1,583


    So I made a topic on this awhile back but it was specifically about getting enemies to take cover but that was specifically on obstacles, what I want to have a real close look at because I think it seems to add a lot more cleverness to how an AI behaves is dodging and even if you watch it all some ridiculous mistakes they react to.

    The above video is of the Halo AI at work, now the grenades are obvious to me, those would be a simple trigger sphere collider, but you can quite clearly see that they're attempting to dodge and move away from the lasers and plasma being shot off. Some of this looks like it's just a fancy dodge animation playing but there are other times when they're deliberately trying to spread out.

    How would somebody mimic this sort of behaviour in Unity?
     
  2. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    A computationally cheap way would be for the victim to maintain a list of units in their field of view and investigate their state. If any of the hostile creatures have recently attacked, the victim should attempt to dodge. That way the AI would attempt to move out of direct lines of fire, but still be shot in the back and from the sides.

    Also do some research on Goal Oriented Action Planning. It's a clever way of handling a bunch of AI goals without having discrete states with concrete transitions.
     
    Lethn likes this.
  3. Lethn

    Lethn

    Joined:
    May 18, 2015
    Posts:
    1,583
    Oh thanks! Wasn't expecting anybody to reply to this, I'll check out what you said, so by field of view would it work in the same way as cone of vision code in stealth games and then executing the dodge animation? That makes a deal of sense because then the A.I has a way of 'seeing' objects and enemies heading towards it the difference is instead of chasing the player and so on I need to activate a dodge animation.
     
  4. GroZZleR

    GroZZleR

    Joined:
    Feb 1, 2015
    Posts:
    3,201
    Yes, exactly. You wouldn't want to dodge every time an enemy is in your line of view though, you'd want to investigate their state and also have some internal cooldown so the victim isn't dodging endlessly.
     
    Lethn likes this.