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

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

Asked by 9 years ago

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

Log in to vote
0
Answered by
Spooce 78
9 years ago

Try this Wiki page on Magnitude. http://wiki.roblox.com/index.php?title=Magnitude

Ad
Log in to vote
0
Answered by 9 years ago

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')

Answer this question