Melee combat vs Ranged combat

So, for my project I have melee specific enemyAI. But, for whatever reason they don’t seem to choose a target for their attacks vs the ranged specific enemyAI, which has no problem choosing a unit to attack. I figured this is something to do with the range of the melee attack being so short. But, how would I go about having those units move towards a player unit it intends to attack rather then them defaulting to 0, 0 on the grid? I have an idea about how to do it, just not super confident on how to implement it.

Basically your MoveActionAI would look for targets and move towards them. If they are reachable within the MaxMoveDistance then it’s simple, you just move directly. If not then you need to move over several turns. The reason they default to 0,0 (actually it’s the lower-left-most position they can go to) is because all move positions have the same value because there’s no target within the MaxMoveDistance.
Find the closest target regardless of distance, calculate the path towards it, and move as much as possible, it will eventually get there in multiple turns.

Make the MoveActionAI always go right next to the target and then the SwordActionAI should be able to trigger the melee action.

1 Like

I feel like I completely understand when it’s said out loud. But, I seem to have trouble implementing it. I’ve been looking over how the ShootAction chooses it’s target and thought I should be able to mirror something similar to that. I haven’t had any luck so far. Every time I think I have given the MoveAction a target it throws a Null reference exemption.

I’m not very experienced with coding. So most of this seems to be going over my head. I really appreciate the quick response.

Privacy & Terms