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 track velocity??

How do I measure velocity so that when it exceeds a certain velocity, the sword tool does damage? I thought about doing something like

if part.Velocity < Vector3(10,0,0) then
    --damage script here
end

until I found out that velocity doesn't work too well with humanoids. If tracking velocity isn't possible, how do I track the speed of an arm? Like when you swing a sword with your right arm, how do you track how fast the sword is travelling?

1 answer

✓ Accepted answer

Think about the physical definition of velocity (speed). It is the distance in which an object travels over a particular period of time. So rather than tracking the velocity, we track these two variables instead:

local tracking = true
local part = game.Workspace.Part -- Part to track

while tracking do
    local initialPos = part.Position
    local elapsed = wait()
    local distance = (initialPos - part.Position).magnitude
    local velocity = distance/elapsed
    if velocity > 10 then
        -- code
    end
end

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