How to rotate camera with a viewmodel's CameraBone/CamPart?

How do I approach making viewmodel camerabone animation? Basically, the viewmodel has a part representing the camera. And I wanna make the camera rotate along with the viewModel.CameraBone.

Some problems I had while trying other methods from different tutorials and forum posts is spinning. Heres an example:

Some solutions I tried was to get the camerabone’s rotation, and multiply the camera’s rotation to the rotation.

Currently, this is the code for the viewmodel without camera rotation

runService.RenderStepped:Connect(function(dt)
		if isEquipped and viewModel then
			local Delta = userInputService:GetMouseDelta()
			SwaySpring:shove(Vector3.new(-Delta.X / 500, Delta.Y / 500, 0))
			BobSpring:shove(Vector3.new(Bob(10), Bob(20), Bob(10)) / 25 * (character.PrimaryPart.Velocity.Magnitude) / 1)
			local UpdatedSway = SwaySpring:update(dt)
			local UpdatedBob = BobSpring:update(dt)
			local UpdatedRecoil = RecoilSpring:update(dt)
			local camera = workspace.CurrentCamera

			viewModel:PivotTo(
				camera.CFrame * 
					CFrame.new(UpdatedSway.X, UpdatedSway.Y, 0) * 
					CFrame.new(UpdatedBob.X, UpdatedBob.Y, 0)
			)

			camera.CFrame = camera.CFrame * CFrame.Angles(UpdatedRecoil.x, UpdatedRecoil.y, UpdatedRecoil.z)
		end
	end)
2 Likes