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 check how fast a part is going?

For example, if I want to damage all parts that hit a surface faster than speed.

1 answer

✓ Accepted answer

Parts have a .Velocity property, which is a vector stating how many studs/second ROBLOX is trying to make the object move.

To get the speed of the part, you can get the .magnitude of the Velocity.

A problem with this approach is that on contact with a surface, ROBLOX may rebound / reduce the speed before your script gets a chance to grab its original velocity.

You can fix that by tracking objects before hand, e.g.

local speed = 0
while true do
	wait()
	local nowSpeed = part.Velocity.magnitude
	-- The speed right now
	speed = speed * 0.5 + nowSpeed * 0.5
	-- We use "speed" instead which is just a bit of a "smoother" speed 
	-- over time.
end

function touched()
	-- Going "speed" studs per second
end

Or, if we're going to be doing this ourselves, we could compute velocity by keeping track of the position it was at and is at now.

A problem with this is that, as I said before, Velocity is the speed ROBLOX is trying to make the object move at. While it might move very slowly for a short bit, once the server has less work to do it it might make it start moving faster.

The Velocity reflects the "actual" velocity; e.g., parts that have a high velocity will hit other objects "harder" (move them more) even if the server shows it moving slower.

1 comment

0

Oh! I never knew about Velocity. Sorry for a bad answer

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