Main NPC script is 'NPCScript.cs' from which all other NPC scripts are derived from and it holds all the main methods.
NPC has 4 main states:
- 'CombatIdle' - NPC is not in combat.
- 'Return2Post' - NPC is in the process of returning to his non-combative job ( guarding or patrolling or else )
- 'CombatWait' – combat wait is a state where a target is set and NPC is chasing target – but attacker limit is reached ( setin 'NPCGuardZone' so NPC stays in a combat zone which is set also in 'NPCGuardZone'.
- 'Combat' – state at which NPC follow the target and when at reach distance – attack.
Currently, NPC target is assigned in 'NPCManager' class and choosing target from list of enemy teams.
NPC target is 'IGameCharacter' interface which both player and NPC implements.
So, both player and NPC can be the target of NPCs.
If you prevent 'NPCManager' to set npc target, you can manualy set target to npc by method 'NPCScript.setTarget(IGameCharacter)'.
Although, NPC behaviour is recomended to modify by one of NPCBehaviour scripts, you can extend NPCScript also by deriving from NPCScript component:
'NPCScript._combat_idle_state()' is method where you can put all npc non combat routine.
Create new script and class derived from 'NPCScript' and override '_combat_idle_state()' method. NPC will do the routine you assign in '_combat_idle_state()' until its attacked. Then it switches to combat or combat wait mode.
After a player is out of guard zone, NPC returns doing its routine again.
You can override each one of the main methods to implement your own methods:
- override '_combat_idle_state()' for non combat routines.
- override '_combat_wait_state()' for combat wait routines.
- override '_chase_state()' for chasing procedure.
NPC animator implements 4 attack animation states. Currently, upon the enemy is reached, the attack is chosen by distance to player and range of attack.
You can choose to start attacks any other way by modifying field ‘chooseAttackMethod()’ in ‘NPCScript’ component.
Attack is started by setting parameter 'pAttack' to true plus setting 'pTriggerType' parameter to number from 0 to and including 3 ( or how ever many attack states you created )
To implement your own way of attack start, look in
'NPCBehaviour.chooseNextAttack()' method and choose how each of the attacks should be started.
On NPC behaviour scripts in its own section: HERE