Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Is there a way to detect the distance between a person, and an object?

For example, a train is coming to the station but it calculates the distance into time, so the players know when it will arrive.

2 answers

Jane drives at an average speed of 45 mph on a journey of 135 miles. To find a time, we need to divide distance by speed.

TL;DR - time = distance/speed

Distance is the magnitude between the two vector positions

local mag = (pos1 - pos2).magnitude

Speed is how fast the object is traveling

local speed = 50 --Not 100% on how to calculate this from velocity. so just use a set variable :P

So to find the time

local speed = 50 --studs a second
local distance = (pos1 - pos2).magnitude
local time = distance/speed

print('object arrives in '..time..' seconds')

This discussion is preserved as it was. New answers, comments, and votes are closed.