Forum rules - please read before posting.

Simple AI for NPCs

I have some zombie NPCs and I need them to perform a simple routine: patrol, detect player, approach to melee distance, attack.

1) Is there a way to do this with AC ActionLists? Any examples would be welcome, since I'm new to AC.

I haven't managed to find a satisfying way to do this, so I am creating a simple script for this AI. It works ok so far, with one flaw: the zombies don't use the NavMesh I have created via AC, and they bump on static obstacles. So here comes question number 2:

2) How can I make a mecanim NPC move around using ACs NavMesh, via script?

Thanks :)

Comments

  • 1) I should start with something of a disclaimer that AC is not intended for traditional, non-combat games - so even simple "chase" AC is not easily possible as its outside of AC's intended scope.

    It's possible if you use custom code, of course - if your zombies didn't rely on AC's NPC scripts but instead a separate system e.g. Playmaker, then you could definitely add that separately.

    As far as doing so within AC, however, you would need to use Variables to keep track of a zombie's state.  A PopUp local variable could have each state as a value: Patrol, Approach, Attack.  I would recommend just working with one zombie, and one variable, until you've gotten it working before moving onto more.

    A single "AI brain" ActionList could be created for the zombie that simply checks this variable every X seconds and reacts accordingly: if the variable is Approach, for example, move towards the player with the Character: Move to point Action (moving towards a Marker placed on the Player).

    Triggers placed on the zombie could be used to detect line-of-sight and player proximity.  The Trigger prefab is a cube, but can be replaced with any shape by changing the collider component.  When the Player enters a Trigger's boundary, you would then change the variable's value.

    But again, as this is basically using AC in a way its unintended for, I think that's a complicated way of doing something that a custom script could do much more efficiently.  You can still merge the two together: when attacking (via custom script), you can still run ActionLists that cause the player to lose health, etc by calling the Interact function.

    2) You will need to provide more detail about what you've done so far.  NPCs and Players both should react to a properly set-up NavMesh - the 2.5D tutorial video covers a practical example of working with AC and Unity Navigation.

    However, you can override AC's internal NavMesh pathfinding code by attaching the Nav Mesh Agent Integration component to a character - this will cause them to rely on a NavMeshAgent component and thus a much more "traditional Unity" way of moving.
  • First off, thanks for the swift answer. Posting a question on Saturday night and having an answer on Sunday morning was far beyond my expectations. :)

    I will revisit the tutorials, check my code once more and try some things based on your remarks before bothering you again.

    Thanks for the feedback, Chris.
  • Hey, I did it.
    After all, I only used my script to determine the state (idle/chase/attack) based on the distance from the player. The actual actions are performed by calling cutscenes from there and AC takes care of the rest, except for damage infliction, which is passed again to the script for more delicate handling.

    Thanks for the feedback, it helped a lot.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Welcome to the official forum for Adventure Creator.