|
So the other week I wrote about pathfinding. After a consultation with our mentor we decided to add some other ai first and if we have the time, implement pathfinding later.

So this week I have been writing code for the enemies’ ai-states. Our two different enemies will have different states when I’m done, but for now they will have the same just so we have something for the alpha. The one to the left is the ranged enemy and the one to the right is melee.


The player, Barney, have three “collision circles” called colliders, the smallest one (the brown circle in the middle) checks if Barney is hit by something (so he will take damage), the next one (the red circle) checks if the enemies are close enough to start attacking (if they are inside they are close enough) and the last one (the blue) is to check if the enemy is too far away to continue its attacks on Barney or too far away and will go back to patrolling. The pictures show the colliders in the prototype (the second picture) and in the actual game (the first picture).
The first state being the “PatrollingState” is active when the enemy is too far away from Barney to attack. The enemies have waypoints which it moves between, when it reaches its destination or collide with a wall it gets a new waypoint to travel to and so on. So far the only state the enemy can switch to from the patrolling state is the “ChargeState”, this happens when the enemy reaches the second collider.
When the enemy enters the charging state it starts with slowing the speed and moving towards Barney. After a short while it get Barneys position and direction, calculating where Barney will be and where to charge. Then it charges with high speed to that point. Then he stops again, moving slowly towards Barney and calculating the next charge point. But if it is outside the biggest collider when stopping it will not charge again, it will go back to the patrolling state and continue patrolling the suit.
Later there will be a state calls “ShootingState” which the other, ranged, enemy will enter instead of the ChargeState. It will change to ShootingState when reaching the second collider. The enemy will stand still and shoot at the point where Barney will be in a short while, calculating that point as the melee enemy in ChargeState. If the enemy is outside the second collider it will move towards Barney until it reaches the collider again where it stops to shoot. If it is outside the third collider it will return to the PatrollingState.
Even later, when all the smaller enemies have their states, I will begin with the bosses’ states.

|