Pathfinding - Enemies wander to 0,0 if out of range

Been working on turning the completed tutorial code into a game and noticed this issue while setting up a new sandbox. The enemies in question only have melee attacks (range of 1) and couldn’t close the distance in a single turn. Instead of standing still or moving forward aimlessly, they all started a rush for GridPosition 0,0. Any idea why this might be? Did anyone find a solution for this? Ideally, I’d like them to move towards the player units in general.

image

Yup that’s intentional due to how the AI is set up, it assigns a value to each action, and by default all move positions have a value of 0, if there isn’t a single position the unit can move to where it would encounter an enemy, then all positions have the same value which is 0 so it goes to the first one on the list which will be the furthest lower left going to 0,0

If you want them to always go towards a player character you need to add that logic to the AI calculation, maybe check the distance to the closest player unit and calculate a value based on that so that it always moves closer even when very far away.

2 Likes

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

Privacy & Terms