I am trying to make a dash by moving the character every heartbeat, and since it runs on a variable frequency i need to account for how long deltaTime was, except i can’t figure out how to do that for a cframe, please advise
local Time = 0
local StartingCFrame = RootPart.CFrame
CC = RunService.Heartbeat:Connect(function(deltaTime)
if Time < Duration then
Time += deltaTime
StartingCFrame *= CFrame.new(0,0,-.75)
RootPart.CFrame = StartingCFrame
end
end)
Delta time is the time that passed from the previous frame, which in most cases it’s 1/60th of a second.
You can just do -.75*deltaTime. -0.75 is a really short distance though so I’m not sure if that’s the distance you actual want to total travel.
You’re basically trying to solve for speed, where time is a constant and distance is a constant.
Would look something like this:
local goalFrame = CFrame.new(0, 0, -5) --Dashes the player 5 studs infront
local maxDashTime = 1 --the amount of time you want the player to dash, so for this example 1 second
local elapsedTime = 0
local connection = nil
connection = RunService.Heartbeat:Connect(function(step)
elapsedTime+=step
rootPart.CFrame = rootPart.CFrame:Lerp(goalFrame, elapsedTime/maxDashTime)
if elapsedTime >= maxDashTime then --When 1 second is elapsed, close connection
connection:Disconnect()
connection = nil
end
end)
well ye that was my problem, i couldn’t solve for speed in a way that would account for the time the step took, some1 taught me this long ago and for the life of me i couldn’t remember. Tbh this still doesn’t give the results that i wanted but it’s by faaaar the closest i’ve got in all my countless attempts with countless methods to make a good dash on roblox. Thanks