Sharp Viewmodel Bobbing. Help needed

Hello Everyone, I am currently trying to make sharp viewmodel bobbing, - mine is really smooth and its all the same speed. This is the effect i want

Here is my code

function updateViewmodelPositionWhenWalk(DT)
	local root = game.Players.LocalPlayer.Character.HumanoidRootPart

	local currentTime = tick()

	if aiming then
		bobSpring:shove (Vector3.new(math.cos(3  * currentTime) * 0.25   * 3  * DT  ,  
			0,  
			math.cos(6  * currentTime ) * 0.5 / 2 * 3 * DT )) 
	else
		if not crouching then
			bobSpring:shove (Vector3.new(math.cos((char.Humanoid.WalkSpeed- 1.8) * currentTime) * (char.Humanoid.WalkSpeed / 100)  * 3  * DT  ,  
				0,  
				math.cos((char.Humanoid.WalkSpeed - 1.8) / 2 * currentTime) * 0.5 * 3 * DT )) 
		else
			bobSpring:shove (Vector3.new(math.cos((12- 1.8) * currentTime) * (12 / 100)  * 3  * DT  ,  
				0,  
				math.cos((12 - 1.8) / 2 * currentTime) * 0.5 * 3 * DT )) 
		end
	end
	--newPos = newPos:Lerp(CFrame.new(-amplitude * math.sin(currentTime * frequency + phase, 0), amplitude * math.sin(currentTime * frequency + phase), 0), -amplitude * math.sin(currentTime * frequency + phase, 0))  -- Generate the new position using a sine wave
end

Does it jsut use animations?

Update : The if not crouching then is the main part of the code

not sure how it implemented, but i assume it will move the head or camera according to the Vector3 ?
we can see it defines Vector3.new(x, 0, z) . x usually means left-right. z means back-forth. y means up-down.
there is no up-down here. and i guess we shouldn’t bob back-forth

No, no ignore this, its a module i use for movement, i jsut want to know if its possible to achieve this effect using math - scripting, or is it only done through animations

we can’t ignore that. i just told you maybe it is ‘smooth’ because it is not bobbing ‘in y direction’ and need confirm with you

it is since in the actual game its kind of weird, basically the Z is the Y or smth like that

okee.

on the other hand, we shall not just use tick() in the equation, and need to use DT.
check my answer to the other similar post to understand the math behind.

to mimic the uneven up-down bobbing from footstep, try use math.abs(math.cos( ... ))

Uh i tried to using this on the cosine waves and it jsut made the up and down motion faster, but it didnt make it like the video]

you use a speedFactor to control the speed

I am sorry I am not that good at understanding sin and cos waves, could you perhaps edit the original script if thats not a problem, also may you elaborate on “speedvector”, again sorry for the inconvenience

local character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local root = character:WaitForChild("HumanoidRootPart")

local tX = 0
local tZ = 0
local speedFactorX = 1 -- you can adjust this for your need
local speedFactorZ = 1  -- you can adjust this for your need

ReplicatedStorage.RenderStepped:Connect(function(dt)
  local speed = root.AssemblyLinearVelocity.Magnitude
  tX += dt * speed * speedFactorX
  tZ += dt * speed * speedFactorZ
  ...
  local bobX = math.cos(tx / (2 * math.pi))
  local bobZ = math.abs(math.cos(tz / (2 * math.pi)))
  bobSpring:shove( Vector3.new(bobX, 0, bobZ) )
end)

Well uh i suppose it gives a new effect, but the viewmodel jsut jumps to the right

see if you need to interchange the X and Z (not sure which mean up, it will have the math.abs)
also try adjust the speedFactorX and speedFactorZ

Same effect when i tried to do these