NPC Characters

Information about the NPC builder demo seen on the home map.

👍

Reminder - Keep Daily Backups

When working on a strategy game with a kit as big as the Complete Kit - always keep a working daily backup! Save yourself the trouble of rolling-back changes and losing work.

How to Setup NPC Characters

The Pro and Complete Kits come with a simple demo of an NPC builder character so you can learn how to construct your own NPC characters wandering in the player village like popular mobile strategy games such as Simpson's Tapped Out or Clash of Clans.

The NPC demo follows a pathfinder around the building construction, like seen below.

800

Click on image to view larger. NPC animation demo

1. Copy the GridManager

You need to look at how the Map01 scene works, and then create a prefab of GridManager so you can include it in the Game scene– the “HomeTown”. What you will get will be the pathfinder grid, that will allow the characters to walk. The pathfinder must be updated when a new building is created or moved on the map, so you will have to replace the normal, plain grass patches with the BattleMap grass, in the BuildingCreator script – these have invisible obstacle cubes in them.

2. Create an NPC Processor

Concerning the behavior of the roaming units, you must create a NPC processor – look at BattleProc for reference, that will control the behavior of existing units, moving freely on the map.

Instead of coordinating the fighter squads by providing them with target buildings and keeping track of other operations concerning the ongoing battle, this controller will have to send random/timed orders to units, manage waypoints – update them when buildings are created or moved, and keep track of the position of existing buildings.

For best performance, as much as possible, make sure that the operations of the NPC processor are one-shot, triggered by user activity on the map, or happening at significant time intervals – you don't need to send state change orders to all 50 units every 0.3 seconds. We've designed the kit so far to use as little state change orders as possible so that the performance is fast on mobile devices.

3. Add In Your Prefab Character

Then, you need to make a copy of the DobbitSoldier prefab, with a different version of FighterController – a modified copy of this script. This controller switches the state between walk and attack – of course, in HomeTown, your NPC will probably just go between waypoints, stay idle or get together, visit and “enter” different buildings, etc.

Everything you need as a reference is already in the kit, but you will be probably be overwhelmed at first – using and expanding it properly will take some time.

🚧

Make sure that in customizing the scripts for NPC, none of the original unit battle scripts are modified – although all the other scripts can be used with no modification – the AnimationController, FighterPath, and FighterPathFinder are not battle-related, they just help the unit walk and change the animations properly while moving.