Using a sine or cosine wave should be able to provide that bobbing motion. This is actually a very good method since you can make the bobbing more aggressive by changing the graph’s amplitude.

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

This code I found on a different post and was just to give you an idea of the math equations and how they are used.

Alright, thanks to you i got a good idea of the math. https://gyazo.com/45636983c026da8f7692eddf580fb4b1
now though. i need to find a way to make the transition from bobbing and idle actually smooth.
any suggestions?

I guess you could use some tweening, try using TweenService:GetValue()

Try this

local TweenService = game:GetService("TweenService")
local TweenTime = 0.3 -- Amount of time for transmission
local startTime = 0
local t = tick()
local function update()
if humanoid.MoveDirection.Magnitude > 0 then
t = tick()
startTime = 0
-- 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
if startTime == 0 then startTime = tick() end
-- do math
local x = math.cos(t * 5) * 0.25
local y = math.abs(math.sin(t * 5)) * 0.25
local alpha = TweenService:GetValue(math.min((tick() - startTime) / TweenTime, 1), Enum.EasingStyle.Cubic, Enum.EasingDirection.Out)
local cf = CFrame.new(x * alpha, y * alpha, 0)
ViewModel.Head.CFrame = Camera.CFrame
end
end

Could I see a GIF? (30 characters)
or you could try increasing tween time
Oh wait I think I Found out what the problem is, change the alpha variable line to local alpha = 1 - TweenService:GetValue(math.min((tick() - startTime) / TweenTime, 1), Enum.EasingStyle.Cubic, Enum.EasingDirection.Out)
I forgot to invert the value so it goes from 1 to 0 instead of 0 to 1

I’m not sure what the problem is but I’ve done some changes here and hopefully it works this time

local TweenService = game:GetService("TweenService")
local TweenTime = 0.3 -- Amount of time for transmission
local startTime = 0
local t = tick()
local function update()
if humanoid.MoveDirection.Magnitude > 0 then
t = tick()
startTime = 0
-- 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
if startTime < 1 then startTime = tick() end
-- do math
local x = math.cos(t * 5) * 0.25
local y = math.abs(math.sin(t * 5)) * 0.25
local alpha = 1- (TweenService:GetValue(math.min((tick() - startTime) / TweenTime, 1), Enum.EasingStyle.Cubic, Enum.EasingDirection.Out))
local cf = CFrame.new(x * alpha, y * alpha, 0)
ViewModel.Head.CFrame = Camera.CFrame * cf
end
end

im having some problems udjusting the intensity of the bobbing, so uh, if you dont mind could i know how?, apparentlly once you change it from the x and y value it’s still not enough. thanks again

local TweenService = game:GetService("TweenService")
local TweenTime = 0.3 -- Amount of time for transmission
local startTime = 0
local Intensity = 1.2
local lastState = 0
local t = tick()
local function update()
if humanoid.MoveDirection.Magnitude > 0 then
t = tick()
if lastState == 0 then lastState = 1 startTime = tick() end
-- do math
local x = math.cos(t * 5) * 0.25
local y = math.abs(math.sin(t * 5)) * 0.25
local alpha = (TweenService:GetValue(math.min((tick() - startTime) / TweenTime, 1), Enum.EasingStyle.Cubic, Enum.EasingDirection.Out))
local cf = CFrame.new(x * alpha * Intensity, y * alpha * Intensity, 0)
ViewModel.Head.CFrame = Camera.CFrame * cf
else
if lastState == 1 then lastState = 0 startTime = tick() end
-- do math
local x = math.cos(t * 5) * 0.25
local y = math.abs(math.sin(t * 5)) * 0.25
local alpha = 1- (TweenService:GetValue(math.min((tick() - startTime) / TweenTime, 1), Enum.EasingStyle.Cubic, Enum.EasingDirection.Out))
local cf = CFrame.new(x * alpha * Intensity, y * alpha * Intensity, 0)
ViewModel.Head.CFrame = Camera.CFrame * cf
end
end

Oh sorry I forgot to reply, It’s a a float between 0 and 1 that I used for tweening, so If I multiply alpha by a value It’s the same as tweening it but this one works with my own calculation, so If i want to start a tween from the middle then I can just give it alpha = 0.5 and then start going up to 1
I used cubic easing so here is how it should look like