I'm having trouble making ranges in tower defense games

Hello dear roblox developers! Today, I am here for a question that I have been thinking about for days but cannot find an answer to.

As you know, there is something called range in tower defense games. This range allows the tower within the range to hit the farthest in the path. And I don’t know how to do that.

unknown

In this image you can see, the transparent blue circle is the color. The farthest enemy in this picture is the enemy named “BLUE”. But the furthest enemy in the range is “GREEN”. Green and red is the range but I want to game to detect green and not red.

1 Like

You could use Magnitude to get all enemies within a range.

I’m not sure how you deal with enemies, but if you do something like a spawn order, where when an enemy spawns its given a number that tells how many enemies have been spawned so far.

Then when getting enemies in range, you loop through all the characters and pick the one with the lowest (first) or highest (last) spawn order to get the one in front.

2 Likes