Enemy behaviour when more than 1 move away from target

So if my enemies are more than 1 move action away from being able to shoot the units they just try and move straight to (0,0)

Animation

[Brainstorming mode on]
I think the solution would be to change the MoveAction.GetEnemyAIAction return value’s actionValue to take into account the pathfinding fCost to get any unit in range, but that may require to check every cell for targetCountAtGridPosition … not sure where I am going with this
[Brainstorming mode off]

Did anyone fix this (or is this just me skipping something maybe)?

2 Likes

When there are no player units in sight, all the valid positions for an enemy returns a score of 0. In your case, the first entry in the list of possible moves is (0,0) so the enemy would just move there. Always.

A few things I would try (in order to not get too complex) is:

  • Check the ‘best’ score and if it’s 0, skip the turn. So the enemy just stays where they are, or
  • Change ActionValue to float and add a small random value to each as we calculate them. That way, the enemies would pick a random position instead of the same one each time, or
  • Add the linear distance to the nearest player unit to the ActionValue so the the enemy at least move in the direction of the player. This is not perfect because (your gif demonstrates) the enemy would not move toward the door, but the wall between player and enemy units.

I personally shy away from the enemy actively ‘hunting’ you (unless this is what I want my enemies to do). For me, the enemies guard a position and should not move a way from it until provoked

4 Likes

Yup the behaviour you are seeing is the intended result based on the simple AI implemented.
Like @bixarrio mentioned there are many ways to expand upon that depending on what design you’re trying to do.
I’m actually currently researching making a mini zombie-defense game based on the course and for zombies the AI that I want to implement is to have them chase the player when spawned regardless of how far, so I just check the position of all players and move towards the closest one, even if it takes multiple turns.
But perhaps you want them to just stay still or guard an area, all those are valid depending on exactly what AI you want your units to have.

2 Likes

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.

Privacy & Terms