Search Unity

Controlling NPC Team Members

Discussion in 'Game Design' started by devinwc, Aug 11, 2020.

  1. devinwc

    devinwc

    Joined:
    Jun 10, 2019
    Posts:
    1
    If this is already covered in some of the Unity Learn tutorials, let me know and I'll start looking around there.

    I want to be able to control NPC Teammates - have them stand guard to shoot enemies, hack a computer, or put up a shield, or (if they're drones) have them detonate to damage enemies. Also, to have the ability to call them back and have them follow me until I need to position them somewhere else again.

    Do you know where I can look to start learning about how to do this? If you've played it, think "Republic Commando" on PC - how you control your squad and tell them where to take up positions to best help on your mission (except in this case, to have the teammates/drones set up in any position to carry out any of their duties). Or if anyone has any thoughts on how to start handling this kind of situation, that would be much appreciated! I don't know if this plays into how to handle the situation at all, but I'm working on this for a VR game. Screen Shot 2020-08-11 at 4.17.31 PM.png
     
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    In general, you'll need two mechanics for this:
    1. Pathfinding - This just allows an object to move from point A to point B in an efficient way. Unity has a built-in pathfinding solution with its NavMesh system. There are other offerings on the asset store, like the A* Pathfinding Project, which are more advanced. Pathfinding is kind of, sometimes referred to as a kind of AI, but it's really just a limited subset of allowing an entity to know how to get from one position to another.
    2. AI - To actually have your agents do something useful, you'll need to have a system that gives them some intelligence. The two most common approaches I've seen are either to build a State Machine, or a Behavior Tree. They're both fairly similar, and the differences can be subtle, so probably either would be okay. There isn't really a built-in solution for this. You can sort of hack the Animator to act as a general state machine, but that's messy. You can also build a state machine with scriptable objects, though that's pretty cumbersome, and there's no visualization. You could look into using Bolt, which is free now. I haven't used it, but it seems to have state machine support. The asset store is full of other offerings as well.
     
    JoeStrout likes this.