NPC Controllers

NPCs (Non-Player Characters) are used to represent the various characters in the game-world that are not controlled by the Player.

An NPC has several components to give it the needed behavior.

Collider

You will have to place a collider on the character, depending on which systems you make use of. Player selection/ targeting of an NPC (via mouse, keyboard or gamepad) will require a collider. The Skills system also require a collider as it uses ray casts to find targets to apply effects on, same with any projectile created by skills. The collider should be created such that it envelopes the NPC but it does not have to be too precise. You can set the collider to be a trigger if you wish, or have to, since it should not matter for most systems.


NPC Controller

This is the basic AI of an NPC and is used to make decisions, like where to move next and actions to perform. This controller does not animate the character so you need to add one of the animation controllers too.

The controller can be added to an object by selecting the character and then choosing from the component menu: plyGame > Character > NPC > NPC Controller.

Detection System

The NPC has a way to detect and ‘engage’ other characters (Player and other NPCs). To ‘engage’ means the NPC makes another character a selected target. The On Detect Characters Event is triggered when the NPC detected one or more characters. The Event is triggered in the Blox on the Character and child objects of the Character object.

The detection system simply detects and optionally select characters. It is up to you to react to this via plyBlox. You should not enable settings that are not needed as it will increase performance when the NPC does not have to do unnecessary checks. So think carefully about which of the settings you change below and why you do it.

plyBlox

The NPC adds various Events and Blocks to plyBlox. The Events can be found under plyGame > NPC while the Blocks will be in various Groups but most will be found under Character.


NPCs need a controller to navigate the scene and move the character. There are a few options and the one you choose will depend on the scenario it is used in. You should have only one of these controllers on an NPC. These controllers can be found on the component menu: plyGame > Characters > NPC > Movement.

No-Move

Use this when the NPC will never have to move around. For example a quest giver NPC that always stand in the same spot or a shop keeper that will never move from behind the counter.

Simple Move

This is a very basic movement option and will move the NPC in a straight line to its destination. It will not try to avoid obstacles and can get stuck. Still a useful option where you know the NPC will not get stuck like when it will only ever follow a predefined path (like a waypoint path).

Pro Move

The Pro movement makes use of Unity’s navmesh based navigation system. This is the movement option you want to choose when you want your NPCs to intelligently navigate around the scene.

You might want to place the Nav Mesh Obstacle component onto the player character so that it and NPCs will interact correctly while moving. This would not needed if your chosen player controller makes use of the Unity navigation system and the player character has its own NavMesh Agent component.

When adding this component a ‘NavMesh Agent’ will also be added. Please have a look at the Unity documentation to learn how to create and bake a navmesh and what the options in the NavMesh Agent means. You might to set Stopping Distance lower or even 0 if you find NPC is struggling to get in range to use a Skill on a character.

--eof--