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

What is DeltaTime and why multiply it with velocity in this script?

Asked by
aredanks 117
4 years ago

This question has been solved by the original poster.

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.

0
delta is used to represent change. delta time is the change in time. royaltoe 5144 — 4y
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? aredanks 117 — 4y
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. vector3_zero 1056 — 4y
0
Thank you aredanks 117 — 4y

Answer this question