Camera CFrame not being accurate

I’m trying to set the cameras cframe z value to 0 but for some reason it gives it the value -3.616 instead of 0. I’ve tried using math.rad() but that doesnt change it. here’s the part of the script causing the issue.

game:GetService("RunService").RenderStepped:Connect(function()
	
	local Y = character.Camera.Y.Value
	local Z = character.Camera.Z.Value
	
	Camera.CFrame = HRP.CFrame * CFrame.new(0,Y,Z) * CFrame.Angles(math.rad(-20),math.rad(ExpectedZRotation),0)

end)
5 Likes

Have you tried switching the values around? Or printing out the expected value

3 Likes

i printed Camera.CFrame.Rotation.Z and it printed 0 every time

3 Likes

Isn’t that what you wanted to happen?

2 Likes

if you print the value it says 0 however if you go into the camera and check the rotation it shows -3.616. the camera is also slightly tilted on the z axis which proves that the rotation isnt actually 0

3 Likes

How are you getting the Y and Z values? Camera is not a property of the player’s character.

Also, the Y and Z values are swapped in your CFrame.Angles()

It should be:

CFrame.Angles(math.rad(-20), 0, math.rad(ExpectedZRotation))

Third, what is the ExpectedZRotation? Is it 0 or a different number?

3 Likes

theres some variables outside the part of the script which i showed which store it. Also expectedzrotation is supposed to be named expectedyrotation. idk why i wrote z instead of y. I kinda figured out a workaround so its fine now.

4 Likes

What was your workaround? (Just because I am curious lol)

2 Likes

idek how this works but here it is. Camera.CFrame = HRP.CFrame * CFrame.new(character.Camera.X.Value,Y, Z + character.Camera.ExpectedZRotation2.Value) * CFrame.Angles(math.rad(-20),math.rad(character.Camera.ExpectedZRotation.Value),math.rad(0+3.616*(character.Camera.ExpectedZRotation.Value/10)))
it’s not perfect but compared to before the tilt is a lot less noticeable. Also btw the Camera in the characters just a folder which stores a bunch of values

3 Likes

That is kind of a mess lol. What is the goal you are trying to accomplish with the camera? It seems like you could just do a bunch of math in a script rather than relying on values stored elsewhere.

1 Like

I don’t know what you’re trying to achieve here, but if you want to change the camera position relative to the character you can just use Humanoid.CameraOffset.

If you want to set the camera to a fixed position, change the camera’s CameraType to Enum.CameraType.Scriptable.

3 Likes

I was making a custom camera system and I was just experimenting with how camera control works cause i’ve never really worked with the camera before. Thanks for the help!

1 Like