Context
Hi. I am currently working on an FPS game and I am currently trying to implement a walking bobble effect for the viewmodel. I encountered an issue where the gun suddenly snaps into place. I know why this occurs, but i do not know any work arounds.
Bobble Code (called every render stepped):
if (humanoidRoot.Velocity - Vector3.zero).magnitude > 1 then
Viewmodel.root.CFrame *= CFrame.new(math.sin(time()*4)/2,math.cos(time()*10)/5,0)
end
Full Function
function renderloop(d)
--// Not by me, I only edited some values
local rotation = workspace.CurrentCamera.CFrame:toObjectSpace(lastCameraCF)
local x,y,z = rotation:ToOrientation()
swayOffset = swayOffset:Lerp(CFrame.Angles(math.sin(x)*3,math.sin(y)*mult,math.sin(y)*mult), .1)
Viewmodel.Root.CFrame = workspace.CurrentCamera.CFrame * swayOffset
lastCameraCF = workspace.CurrentCamera.CFrame
--\\
if (humanoidRoot.Velocity - Vector3.zero).magnitude > 1 then
Viewmodel.Root.CFrame *= CFrame.new(math.sin(time()*4)/2,math.cos(time()*10)/5,0)
end
end