Camera CFrame is acting weird

Hi I want to make this script rotate the character’s camera to the left and then to the right, but it doesn’t work when it should work

Here is the script:

local RotatingValue = 0.01



local rus = game:GetService('RunService')

local plr = game.Players.LocalPlayer










while wait(1) do

	
	

	RotatingValue = RotatingValue *(-1)
	
	
	local cf: CFrame = CFrame.new(
		0, 0, 0, 

		1, 0, RotatingValue, 
		0, 1, 0, 
		0, 0, 1 
	)

	print(cf.ZVector.X)
	print(RotatingValue)
	

	local function cameraFunction()
		workspace.CurrentCamera.CFrame *= cf 
	end


	rus:BindToRenderStep(
		'funny camera', 
		Enum.RenderPriority.Camera.Value + 1, 
		cameraFunction 
	)
end



And here is also a video:

The problem is when rotation value is set to -0.01 the camera is rotating but when it is set to 0.01 then it is not rotating

Change the “RotatingValue = RotatingValue *(-1)” to “RotatingValue = RotatingValue *(1)”

1 Like

After i changed it it starts rotate like this:

Okay so I can clear up some of the confusion - do you want something like this?
https://gyazo.com/b13cf2ed171b1ab251cee6c5bb93db28

Yeah exactly that’s what i’m looking for

local Players = game.Players
local Player = Players.LocalPlayer
local RotatingValue = 0.01
local FlipFlop = 0
local rus = game:GetService('RunService')
local plr = game.Players.LocalPlayer
 
while wait(1) do

FlipFlop = FlipFlop + 1

	if FlipFlop % 2 == 0 then
		print("flip")
		
		RotatingValue = RotatingValue *(-1)
		
	else
		print("flop")
		RotatingValue = -RotatingValue *(-1)
	end
	
	local cf: CFrame = CFrame.new(
		0, 0, 0, 

		1, 0, RotatingValue, 
		0, 1, 0, 
		0, 0, 1 
	)

	local function cameraFunction()

		workspace.CurrentCamera.CFrame *= cf 
	end

	rus:BindToRenderStep(
		'funny camera', 
		Enum.RenderPriority.Camera.Value + 1, 
		cameraFunction 
	)
end

All I did was add a flipflop value, basiaclly when it loops it add 1 to the value and checks if the value is either odd or even and if its odd it flips one way and if its even it flips the other.

1 Like

Thank you so much i was not able to solve this for long time

1 Like

You should mark their post as the solution so that they get credit for solving peoples problems!

1 Like