I want to figure out why the Z value in the rotation changes even though I set it to 0
I have looked at many CFrame explanations but I don’t see how they can help my issue.
Ive tried setting it to 0 afterwards but that breaks things more.
Im looking for a way to make just the Z rotation value 0.
my current code is this:
ContextActionService:BindAction("MouseMovement",function(name,state,input:InputObject)
local delta = input.Delta
if delta == blank then return end
print(delta)
Camera.CFrame += delta
script.Parent.Base.CameraAttachment.WorldCFrame = script.Parent.Base.CameraAttachment.WorldCFrame * CFrame.fromEulerAngles(math.rad(delta.Y * -1),math.rad(delta.X * -1),0) -- This is the issue
print(script.Parent.Base.CameraAttachment.WorldCFrame.Rotation)
end,false,Enum.UserInputType.MouseMovement)
Keep in mind this is for a drone camera rotation script in my game.
(and yes my code is a little messy)
The fourth argument for CFrame.fromEulerAngles defaults to being applied in XYZ order whereas Roblox orientation is applied in YXZ order. You would have to set the 4th arg to Enum.RotationOrder.YXZ, or just use fromEulerAnglesYXZ.
Oh you know what, I completely overlooked the fact you’re multiplying it by an attachment’s WorldCFrame
local targetCFrame = script.Parent.Base.CameraAttachment.WorldCFrame
-- first we get rid of the Z axis
local x, y = targetCFrame:ToEulerAnglesYXZ()
script.Parent.Base.CameraAttachment.WorldCFrame = CFrame.new(script.Parent.Base.CameraAttachment.WorldPosition) *
CFrame.fromEulerAnglesYXZ(x, y, 0) *
CFrame.fromEulerAnglesYXZ(math.rad(-delta.Y), math.rad(-delta.X), 0)
If this doesn’t work, you might have to reconstruct the CFrame entirely using the attachment’s parent’s CFrame