Confused over some example code

So I was looking at some of the example code Roblox provides for head bobbing.

The code that's just kinda plastered in the page for humanoids for some reason.
local RunService = game:GetService("RunService")

local playerModel = script.Parent
local humanoid = playerModel:WaitForChild("Humanoid")

local function updateBobbleEffect()
	local now = tick()
	if humanoid.MoveDirection.Magnitude > 0 then -- Is the character walking?
		local velocity = humanoid.RootPart.Velocity
		local bobble_X = math.cos(now * 9) / 5
		local bobble_Y = math.abs(math.sin(now * 12)) / 5

		local bobble =, bobble_Y, 0) * math.min(1, velocity.Magnitude / humanoid.WalkSpeed)
		humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble, 0.25)
		-- Scale down the CameraOffset so that it shifts back to its regular position.
		humanoid.CameraOffset = humanoid.CameraOffset * 0.75


And I’m very confused over one segment.

So tick is set at local now = tick and then used at local bobble_X = math.cos(now * 9) / 5
and local bobble_Y = math.abs(math.sin(now * 12)) / 5

This confuses me because tick is a continually increasing number, and last I checked, you needed to subtract the elapsed time from it, but this script just straight up doesn’t at any point, yet somehow this doesn’t completely mess with it and I can’t grasp why.

1 Like

Even if tick is a continually increasing number,

let’s say a function like y = x, the output y will increase forever

If you put it inside sin it doesn’t because it’s a periodic function.


While I don’t entirely understand, ah.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.