Calculating the position from 2 positions is pretty easy, but that’ll give you the distance in studs, so you’ll have to run the result through some math to calculate miles/kilometers.
function GetDistance(Position1, Position2)
return (Position1 - Position2).Magnitude
end
print(GetDistance(Vector3.new(0, 0, 0), Vector3.new(5, 0, 0))) --// This should print 5
--// And, to only calculate the X and Y position,
local Position1 = Vector3.new(5, 5, 5) * Vector3.new(1, 1, 0)
--// This sets the vector from 5,5,5 to 5,5,0
--// Essentially, removing an axis from the number.
As for getting kilometers or miles, thats dependent on you and how many studs your game counts as a mile or kilometer.
For example:
local Distance = 5000
local StudsPerKilometer = 500 --// Every 500 studs is 1 kilometer
local StudsPerMile = StudsPerKilometer / 1.609 --// Math to determine miles
local Kilometers = Distance / StudsPerKilometer
local Miles = Distance / StudsPerMile
print(Kilometers, Miles)
As for the rope example linked, I remember doing something similar but the same math I did in the first code block worked just fine.
If I misunderstood anything, please let me know as I don’t exactly know what you’re trying to do.