Back

Tuesday 14.6 | Enemy Combat

Platformer Prototype

Adding basic functionality for enemy combat. I will probably be refining and adding effects to this for the rest of the week.

Behaviour Tree & Enemy Script Relationship

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.

Behaviour Tree Chasing/Attacking Node

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);
	}

EnemyBehaviour (Main enemy script)

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.

SecondaryAttack CoolGuyStats

Day's Work

  • Enemy combat
    • "Guard" Behaviour Tree
      • Attacking/Chasing sets the EnemyBehaviour state to Chasing and Attacking
    • EnemyBehaviour
      • Enum EnemyState
      • Frequency of secondary attacks determined by ScriptableObject EnemyStats
      • Attack speed corresponds to animation length
        • Animation length has to be 2s
        • Animation speed is 2 and changed with "Attack Speed" parameter
    • Secondary attack animation
    • Small fixes
Back