How would I go for calculating closest path distance?

An AI for my tower defense game I scripted calculates and target based on magnitude atm.
So what I’m trying to achieve, is I want it to target like shown

1 Like

Have you tried raycasting inside the magnitude? If not that would probably work. Additionally another thing you could try is something like naming each thing that spawns a number > like enemy1, enemy2, ect < that might be janky, but it is an option lol.

You could loop through all of the AI and subtract the absolute value of the magnitude of both:

local best
for i, shoot in ipairs(chars) do
   if i == 1 then
       best = (math.abs(shoot.Position.Magnitude) - math.abs(other.Position.Magnitude)) 
   else
       if (math.abs(shoot.Position.Magnitude) - math.abs(other.Position.Magnitude)) < best then
           best = (math.abs(shoot.Position.Magnitude) - math.abs(other.Position.Magnitude))
       else
           print("Not a better solution")
       end
   end
end
1 Like

Okay I’ll try that. I will be using nodes for each corner to detect the closest path.

3 Likes