Adding basic functionality for enemy combat. I will probably be refining and adding effects to this for the rest of the week.
I implemented the combat state management system pretty weird. I have some functionality in the behaviour tree nodes and some in the EnemyBehaviour script (driven by the behaviour tree though). I have some concerns but first, here's roughly how chasing and attacking works at the moment.
Pseudocode:
if (PlayerInAttackRange && IsFacingPlayer)
enemy.state = EnemyBehaviour.EnemyState.Attacking;
else
{
enemy.state = EnemyBehaviour.EnemyState.Chasing;
// If target in range but not facing it turn it
if (PlayerInAttackRange)
RotateTowardsPlayer();
navMeshAgent.SetDestination(playerPosition);
}
Pseudocode:
Update()
{
switch (state)
{
case EnemyState.Patrolling:
Patrolling();
case EnemyState.Chasing:
Chasing();
case EnemyState.Inspecting:
Inspecting();
case EnemyState.Attacking:
Attacking();
case EnemyState.Dead:
break;
}
}
I did this partly because I found it easy to implement the attacking loop fully in the EnemyBehaviour. I'm worried that this might cause issues when implementing the stealth and such, but I'll have to look into it tomorrow and decide how I'm going to approach this.