I see some scripts that use deltaTime and in an example I see, it is the returned parameter of Stepped event. The script uses deltaTime to multiply by a player’s humanoidrootpart velocity, I want to understand what multiplying velocity by time gives and what ‘delta’ means in deltaTime?


local leeway = 2 -- How many studs of leeway can the player have before they are stopped? Low values = more rubber banding during lag!
local player = aPlayer
local RunService = game:GetService("RunService")
local lastPosition
RunService.Stepped:Connect(function(deltaTime)
    local character = player.Character
    local humanoid = character:FindFirstChildOfClass("Humanoid")
    if character and character.PrimaryPart and humanoid then
        local maxSpeed = math.max(humanoid.WalkSpeed, humanoid.JumpPower) + leeway
        character.PrimaryPart.Velocity = character.PrimaryPart.Velocity.Unit * (math.min(maxSpeed, character.PrimaryPart.Velocity.Magnitude)) -- Limit their velocity!
        local currentPosition = character:GetPrimaryPartCFrame()
        if lastPosition then
            local deltaPosition = currentPosition.p-lastPosition.p
            if deltaPosition > character.PrimaryPart.Velocity*deltaTime + leeway then -- Check if they are moving faster than their velocity!
                character:SetPrimaryPartCFrame(lastPosition) -- Reset their position!
            end
        end
        lastPosition = currentPosition
    else
        lastPosition = nil
    end
end)

Note: This is not my script and it is meant to stop flying, an anti-exploit script.

4 comments

0

delta is used to represent change. delta time is the change in time.

0

Ahh thank you that makes sense but why multiply deltaTime by velocity? What does the change in time have to do with physics calculations?

0

Multiplying velocity by deltaTime makes movement speed frame rate independant. If you don't do it then people with lower frame rates will move slower, and vice versa.

0

Thank you