Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Is there a way to get the distance between two objects?

Asked by 10 years ago

Is there a way to get the distance between two objects? I looked for this on the wiki but I didn't find anything. If it is possible, I want to make is so that if an object gets within a certain distance, something would happen.

1 answer

Log in to vote
3
Answered by 10 years ago

If checking the distance between a player and an object:

function getDistance(player, object)
    return player:GetDistanceFromCharacter(object.Position)
end

Otherwise, use the following.

function getDistance(object1, object2)
    return (object1.Position - object2.Position).magnitude
end

Both functions return the distance in studs between the two objects (or player and object).

0
Thanks GloriousOromis 10 — 10y
Ad

Answer this question