I’m trying to make it to where only above a certain walk speed, character lerping is active. Like for sprinting but not normal walking.
The issue is I can’t figure out what’s the problem with the script.
game.Players.LocalPlayer.Character.Humanoid.WalkSpeed <= 16 then
function Lerp(a, b, t)
return a + (b - a) * t
end
local STEP = 0.1
local RunService = game:GetService("RunService")
function getYaw(vec)
return -math.atan2(vec.Z, vec.X) - math.pi/2
end
local lastFrameDir = script.Parent.HumanoidRootPart.CFrame.lookVector
local lastDir = lastFrameDir
local dir = lastDir
local accum = 0
local rollGoal = 0
local roll = 0
RunService.Stepped:Connect(function(t, dt)
accum = accum + dt
lastFrameDir = dir
dir = script.Parent.HumanoidRootPart.CFrame.lookVector
local angleDiff = getYaw(dir) - getYaw(lastFrameDir)
angleDiff = (angleDiff + math.pi/2) % math.pi - math.pi/2
local sign = angleDiff < 0 and -1 or 1
if accum > STEP then
local diff = 1 - lastDir:Dot(dir)
rollGoal = diff * math.rad(40) * sign
lastDir = dir
accum = 0
end
roll = Lerp(roll, rollGoal, 0.2)
script.Parent.LowerTorso.Root.Transform = script.Parent.LowerTorso.Root.Transform * CFrame.Angles(0, 0, roll)
end)
Can anyone tell me the problem?