I was wondering, I have my combat system up and ready to go and does well but I wanna be able to attack the closest person to me in the direction I’m facing, so I don’t attack somebody that comes in for an attack and ends up closer or if I hit my enemy in a field of enemies and start jumping from one enemy to another.
The easiest thing would be to give the player an extra sphere collider.
Each enemy beginning overlap with it, registers itself as actor to an array of actors innthe player… And removes himself when leaving the overlap.
And the player, on firing/attacking, just foreach iterates the array, gets his location and the actor location of the current iterated enemy… Gets the distance of both… And the shortest distant enemy will be returned as target.
Why the collider?
To not iterate over every enemy in the whole level map, just the closest ones.