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

How do i calculate time from speed and distance?

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

3 comments

0

distance/speed = time.

0

Remember that speed = distance/time, so speed*time = distance and distance/speed = time.

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

2 answers

✓ Accepted answer
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

2 comments

0

Wow dude thanks

0

indent please and use local variables for faster indexing since globals are adding to the registry and not the stack.

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!

2 comments

0

Yeaah i know htat formula already, but i dont know how to make Studio interpretate it, like what functions sohuld i use?

0

ill put a script

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