Hey there! So, I was making a walking animation for a viewmodel (display arms) for my fps game and I came across a bug (well, not really a bug). It wouldn’t tween to the middle, instead, it would instantly go to the middle. Maybe this code will explain what i’m trying to say more thoroughly:
function update()
Mag = humanoid.MoveDirection.magnitude
if humanoid.MoveDirection.magnitude > 0 then
-- Moving
local currentCF = cam.CFrame
local t = tick()
local x = math.cos(t * 5) * .25
local y = math.abs(math.sin(t * 5)) * .25
local cf = currentCF * CFrame.new(x, y, 0)
CFF = cf
else
-- Idle, do nothing
if Mag > 0 then
-- Just stopped
local alpha = .5
CFF = CFF:lerp(cam.CFrame, alpha)
else
CFF = cam.CFrame
end
end
gun:SetPrimaryPartCFrame(CFF or cam.CFrame)
end
run.RenderStepped:Connect(update)
I hope somebody can help. Thanks!
- Dragon