Hello!
So, I know there’s a way to get the distance like mostly everyone does like this (p1 - p2).Magntiude. And it works fine in most cases. But I’m making a tracker tool and I need it to be able to get the distance of the part even if they’re behind a wall.
To give a better understanding, this is not how I need it to act:
I don’t really have a clue on how to do this without using a service, maybe utlizing PathfindingService to find a path from one player to another and then adding up the magnitudes between the points would work?
This is the code for anyone wondering, if they do get on this post someday.
local PathfindingService = game:GetService("PathfindingService")
local path = PathfindingService:CreatePath()
path:ComputeAsync(workspace.Part1.Position, workspace.Part2.Position)
local waypoints = path:GetWaypoints()
local totalDistance = 0
local function getMagnitude(p1, p2)
return (p1 - p2).Magnitude
end
for i, waypoint in pairs(waypoints) do
local nextWP = waypoints[i + 1]
if nextWP then
totalDistance += getMagnitude(waypoint.Position, nextWP.Position)
end
end
print(totalDistance)