Aeterna Blog #3
Situation: Start adding more functionality to the game, including player movement and AI attacks.
Task:
- Create close attack logic
- Create ranged attack logic
Action: Using unitys behaviour graphs, I created custom close and ranged attack nodes, two blackboard enums, one to hold attack state (Cooldown, Ready, Attacking) and current attack type (Ranged, Close) and a scriptable object to hold the enemies' prefabs (projectile prefabs etc)
The enemy starts its life by setting the target, which is the first (and only) gameobject with the tag "Player".
While it isn’t attacking, it will move towards the player.
During the cooldown state, the logic will wait two seconds before picking an attack. It will simply pick a random attack between close and ranged. They will then be set to the Ready state.
During the ready state, the logic will check if they are close enough for that specific attack. Currently it is hard coded to 5 for ranged and 2.5 for close but later will be implemented into another scriptable object for expandability. If they are in range, they will be set to Attack state.
During the attack state, it will play the attack node based on its attack state. To give the player a warning for a ranged attack, the enemy will stop and charge for 2.5 seconds then attack. After attacking, they will return to the cooldown state.
Result: Core attack and decision logic is in place. Currently enemies still walk until they are right next to the player and have no models. This is a good starting place to expand onto new enemies and create better looking attacks and enemies.