I’ve done some searching to try and make or find a script that would recreate a turning player walk as seen in this reference of another game here:
I have found a script but it is made for r15 and I need a hand with converting it to r6 and also making the head move slightly towards the way the player is moving (only left or right).
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)
No I’m trying to make the script compatible and work for r6 as it is made for r15, on top of this I am trying to make the head turn slightly left or right depending on which way the player is going.
I did that, however it is still not working as desired.
It doesn’t actually lean/tilt the player it just glitches the player and doesn’t tilt at all.
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
wait(.2)
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.Torso.CFrame = script.Parent.Torso.CFrame * CFrame.Angles(0, 0, roll)
end)