{"__v":2,"_id":"550d801711e8d00d00b80380","category":{"__v":7,"_id":"550a4c2e42fff40d00ae6049","project":"543b9b0065bf840e00b473d5","version":"543b9b0065bf840e00b473d8","pages":["550a4d06492cbf0d00bbff79","550a870cb6fd572500a57a42","550d801711e8d00d00b80380","551e00f5a7e98017009e3ee4","551edb36c2d1ec1700b4261c","554f09c6a8c1ae0d00c5bb93","55b63d63f8105a2f00c34e33"],"reference":false,"createdAt":"2015-03-19T04:10:22.740Z","from_sync":false,"order":3,"slug":"units","title":"Units"},"project":"543b9b0065bf840e00b473d5","user":"543b9aa865bf840e00b473d1","version":{"__v":11,"_id":"543b9b0065bf840e00b473d8","project":"543b9b0065bf840e00b473d5","createdAt":"2014-10-13T09:27:28.467Z","releaseDate":"2014-10-13T09:27:28.467Z","categories":["543b9b0065bf840e00b473d9","543b9ef065bf840e00b473e0","54890012f291f61400c02d36","54890902f291f61400c02d3e","54890c43f291f61400c02d44","54890d71c178b40b00aa3086","5508125c0c4d8c19008a5f83","55094050961f17170070abbd","550945111c38c50d006118ad","550a4c2e42fff40d00ae6049","55221c074801a40d00a77610"],"is_hidden":false,"is_beta":false,"is_stable":false,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"createdAt":"2015-03-21T14:28:39.060Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"auth":"required","params":[],"url":""},"order":5,"body":"[block:callout]\n{\n  \"type\": \"success\",\n  \"title\": \"Available Only in the Pro and Complete Kit\",\n  \"body\": \"The Starter Kit does not come with the message console. [Learn more about Pro/Complete kits here](https://www.citybuildingkit.com/#pricing)\"\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"How to Setup NPC Characters\"\n}\n[/block]\nThe 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.\n\nThe NPC demo follows a pathfinder around the building construction, like seen below.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://www.filepicker.io/api/file/wK2oLrC7SrS6h6AmrO3f\",\n        \"npc-character.jpg\",\n        \"800\",\n        \"600\",\n        \"#67491e\",\n        \"\"\n      ],\n      \"caption\": \"NPC animation demo\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"1. Copy the GridManager\"\n}\n[/block]\nYou 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.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"2. Create an NPC Processor\"\n}\n[/block]\nConcerning 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. \n\nInstead 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. \n\nFor 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.\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"3. Add In Your Prefab Character\"\n}\n[/block]\nThen, 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.\n\nEverything 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.\n[block:callout]\n{\n  \"type\": \"warning\",\n  \"body\": \"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.\",\n  \"title\": \"\"\n}\n[/block]","excerpt":"Information about the NPC builder demo seen on the home map.","slug":"npc-characters","type":"basic","title":"NPC Characters"}

NPC Characters

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

[block:callout] { "type": "success", "title": "Available Only in the Pro and Complete Kit", "body": "The Starter Kit does not come with the message console. [Learn more about Pro/Complete kits here](https://www.citybuildingkit.com/#pricing)" } [/block] [block:api-header] { "type": "basic", "title": "How to Setup NPC Characters" } [/block] 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. [block:image] { "images": [ { "image": [ "https://www.filepicker.io/api/file/wK2oLrC7SrS6h6AmrO3f", "npc-character.jpg", "800", "600", "#67491e", "" ], "caption": "NPC animation demo" } ] } [/block] [block:api-header] { "type": "basic", "title": "1. Copy the GridManager" } [/block] 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. [block:api-header] { "type": "basic", "title": "2. Create an NPC Processor" } [/block] 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. [block:api-header] { "type": "basic", "title": "3. Add In Your Prefab Character" } [/block] 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. [block:callout] { "type": "warning", "body": "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.", "title": "" } [/block]