Manipulating Camera in First Person Rotates character

I was attempting to add some “realistic bobbing” for the players camera whenever they were walking and I’m happy with the end result.
However, I noticed when I held a tool it swayed from left to right, and I found out that somehow the entire character rotates left and right.
No clue why its happening, its a nice addition honestly but I’d like to understand how this is happening.
Clip of it happening here, Left is my point of view and the right is the server view.

woops, clip didnt upload correctly, getting a better one
Edit: clip software I use wont do it for some reason, but the POV one shows what I mean anyway.

1 Like

Are you sure that’s not due to your character’s animation bundle?

Also forgot the code, its a local script in StarterCharacterScripts

local RS = game:GetService('RunService')
local Players = game:GetService('Players')

local plrcam = workspace.CurrentCamera
local char :Model = script.Parent
local hum = char:FindFirstChildOfClass('Humanoid')


-- Values for bobbing correctly
local BASE = 18
local Distance = 8
local Speed = 0.2

local function CalibrateCam()
	
	local plrVelocity = char.PrimaryPart.AssemblyLinearVelocity
	
	local velcheck = Vector3.new(plrVelocity.X, 0, plrVelocity.Z).Magnitude
	
	local VelocityMod = velcheck / BASE
	local nspeed = Speed * VelocityMod
	local xpos = math.cos(tick() * Distance) * nspeed
	local ypos = math.sin(tick() * Distance * 2) * nspeed / 2
	local boboffset = CFrame.new(xpos, ypos, 0)

	--Final
	plrcam.CFrame = plrcam.CFrame * boboffset 
	
end

RS.RenderStepped:Connect(CalibrateCam)

I believe I’m just changing the position of the camera, how does that correlate to the character moving?

It’s in R6, should’ve mentioned.

tick() is semi outdated consider using os.clock() (sorry i had insane urge to tell you that for no reason)

Really? Had no idea. Appreciate pointing that out though, thank you!
When knowing about wait() and task.wait() I always was a little unsure if things I was using were the more up-to-date version.

2 Likes