Calculating the distance from one coordinate to another

I’ve been figuring out a way to calculating the distance from one coordinate to another using the X,Y axis and It’s giving me trouble.

I’d resorted into making calculations using this post, but I’ve have gotten nowhere due to the fact that I cannot calculate that much of a number:

A basic example of what I’m trying to achieve
image

(not accurate… or is it?)

1 Like

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.

3 Likes

I found that one stud is 28cm by default, so a meter is ~357 studs and a kilometer would be ~357142 studs.

No your good, this is exactly what I’m trying to do.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.