Hello! This post is a continuation of my previous post that was about bobbing a ViewModel when a player moved. I found out a way to create bobbing for a ViewModel, hooray! But another problem arose from this, which is the snapping.
I have an “if else” statement that runs every frame. If you are moving, do the bobbing on the ViewModel. Else, snap the ViewModel to the Camera’s CFrame. The problem is the snapping.
local function update()
local t = tick()
if humanoid.MoveDirection.Magnitude > 0 then
-- do math
local x = math.cos(t * 5) * 0.25
local y = math.abs(math.sin(t * 5)) * 0.25
local cf = CFrame.new(x, y, 0)
ViewModel.Head.CFrame = Camera.CFrame * cf
else
ViewModel.Head.CFrame = Camera.CFrame
end
end
game:GetService("RunService").RenderStepped:connect(update)
The problem is that when the player stops moving, the bobbing stops and moves the ViewModel instantly to the player’s Camera, vice-versa. The result is a ViewModel that looks like it snaps to the Camera when still. I want the ViewModel to visibly return to the player’s Camera. I have tried Lerping but the effect is off and not what I am looking for.
Any tips would help.