Changing math.sin() speed

Hi, so I made a little camera bob system, but I have one small issue
How can I reduce/increase the speed of math.sin()?

local RS = game:GetService('RunService')

function updatebob(deltatime)
	
	local Player = game.Players.LocalPlayer
	local Character = Player.Character
	
	local Humanoid = Character.Humanoid
	local Camera = workspace.CurrentCamera
	
	if Humanoid.MoveDirection.Magnitude > 0 then
		local OFFSET_BOBBLE_Y = math.sin(deltatime * 2) * 0.2
		local CAMERA_BOBBLE_Z = math.sin(deltatime * 20) * 0.2
		
		local RESULT_OFFSET = Vector3.new(OFFSET_BOBBLE_Y,OFFSET_BOBBLE_Y,0)
		local RESULT_CFRAME = CFrame.Angles(0,0,CAMERA_BOBBLE_Z)
		
		Camera.CFrame = Camera.CFrame:Lerp(Camera.CFrame * RESULT_CFRAME, .25)
		Humanoid.CameraOffset = Humanoid.CameraOffset:Lerp(RESULT_OFFSET, .25)
	else
		
	end
end

RS.RenderStepped:Connect(function(dt)
	updatebob(tick())
end)

Here’s the script ^^^^

1 Like
local OFFSET_BOBBLE_Y = math.sin(deltatime * 2) * 0.2
local CAMERA_BOBBLE_Z = math.sin(deltatime * 20) * 0.2

You would have to multiply the parameter inside math.sin in order to change the speed, for example:

local YSpeed = 4
local ZSpeed = 40

-- ^^ These two were previously 2, 20, now I duplicated them

local OFFSET_BOBBLE_Y = math.sin(deltatime * YSpeed) * 0.2
local CAMERA_BOBBLE_Z = math.sin(deltatime * ZSpeed) * 0.2
2 Likes

The lower the slower? Or is it the opposite?

1 Like

This is also a solution, thanks

Yep, when you increase the values you are pretty much multiplicating the time, if you double the value, you double the deltaTime, therefore it’s two times faster.

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