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

How do i calculate time from speed and distance?

Asked by 5 years ago
Edited 5 years ago

So lets say i have an brick moving really fast, i want to calculate the time it will take for it reach to the target brick, how can i do that? Is there any function i can use to do that?

( brick is moving straight)

Heres a image representation of what i mean :p

https://prnt.sc/mtung0

0
distance/speed = time. User#25115 0 — 5y
0
Remember that speed = distance/time, so speed*time = distance and distance/speed = time. User#25115 0 — 5y
0
Yeah but i dont know what functions i can use to calculate the brick its gonna hit, distance from that brick and time it will take Igoralexeymarengobr 365 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago
local function GetTimeToReach(part,part2,speed)--This calculates the time.
return GetDistance(part,part2)/speed
end

local function GetDistance(part,part2)--This calculates the distance of part from part2
return (part.Position-part2.Position).Magnitude
end

--Ex: The part speed is 2 studs per second

while wait() do
local TimeToImpact=GetTimeToReach(Part,Wall,2)
print("Distance: "..GetDistance(Part,Wall).." Studs. Time to impact: "..TimeToImpact)
end

0
Wow dude thanks Igoralexeymarengobr 365 — 5y
0
indent please and use local variables for faster indexing since globals are adding to the registry and not the stack. EpicMetatableMoment 1444 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

So take you distance, which for example might be 5 studs, and then take the speed, which might be 1 studs per second, then insert it into this formula: distance --------- = time speed In the example, the formula would be as follows: 5 studs --------- = 5 seconds 1 stud per second So just use that formula and you should be able to figure it out! Accept this answer if it solved your problem!

0
Yeaah i know htat formula already, but i dont know how to make Studio interpretate it, like what functions sohuld i use? Igoralexeymarengobr 365 — 5y
0
ill put a script CaptainD_veloper 290 — 5y

Answer this question