How can I make camera bobble quicker?

When the player walks, the camera bobbles back and forth. I made it so that the higher their walkspeed, the stronger the bobble effect will be. However, I want the bobble to also move back and forth quicker, though when I try to do this by speeding up the CT, the transition becomes all choppy and bad. The end result works, however getting there is the issue.

Is their any other way to fix this?

It might be hard to notice in the video, but you can see it hops/chops when switching from walking to sprinting.

local Players = game:GetService("Players")
local TS = game:GetService("TweenService")
local RunService = game:GetService("RunService")

local Player = Players.LocalPlayer
local Char = game.Workspace:WaitForChild(Player.Name)
local Humanoid = Char:WaitForChild("Humanoid")
local Values = Char:WaitForChild("Values")

local walkTweenInfo = TweenInfo.new(0.2, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local idleTweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)

local currentTween
local targetOffset = Vector3.new(0, 0, 0)

RunService.RenderStepped:Connect(function()
	if Values.Swimming.Value == true then return end
	local CT = tick()
	
	if Humanoid.MoveDirection.Magnitude > 0 and Humanoid:GetState() == Enum.HumanoidStateType.Running then
		local BobbleX = math.cos(CT*Humanoid.WalkSpeed / 2)*(Humanoid.WalkSpeed / 25)
		local BobbleY = math.abs(math.sin(CT*Humanoid.WalkSpeed / 2))*(Humanoid.WalkSpeed / 25)
		targetOffset = Vector3.new(BobbleX, BobbleY -.2, 0)
		
		if currentTween then
			currentTween:Cancel()
		end
		
		currentTween = TS:Create(Humanoid, walkTweenInfo, {CameraOffset = targetOffset})
		currentTween:Play()
	else
		local BobbleX = (math.cos(CT * 2) + math.cos(CT * 1.5)) * 0.1
		local BobbleY = (math.sin(CT * 2.5) + math.sin(CT * 1.7)) * 0.1
		targetOffset = Vector3.new(BobbleX, BobbleY, 0)
		
		if currentTween then
			currentTween:Cancel()
		end
		
		currentTween = TS:Create(Humanoid, idleTweenInfo, {CameraOffset = targetOffset})
		currentTween:Play()
	end

	Humanoid.CameraOffset = Humanoid.CameraOffset:lerp(targetOffset, 0.1)
end)
4 Likes

In its current state, the TweenService seems to be trying to interpolate between two significantly different values within the TweenInfo paramters in a short amount of time so it isn’t going to be smooth by the looks of it.

Give this a try:

local walkTweenInfo = TweenInfo.new(0.1, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local idleTweenInfo = TweenInfo.new(0.25, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)

Its not that, the transition is normally fine, however when I try to scale the CT thats when it messes up. Usually, it’s:
local BobbleX = math.cos(CT5)(Humanoid.WalkSpeed / 25)

However, since I want to scale the speed, I do this:
local BobbleX = math.cos(CTHumanoid.WalkSpeed / 2)(Humanoid.WalkSpeed / 25)

The issue is the increase in CT which causes it to bug out, but that’s the only way I can make it quicker, at least from what I can see.