Controlling NPC Team Members

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.

In general, you’ll need two mechanics for this:

  • 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.
  • 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.
1 Like