MouseDelta camera rotation & locking z axis to world

Ive run into this problem while making this freecam script, I’ve scowered fourms for an answer to no avail.
I’m getting this unwanted z axis rotation because the cframe is going off the cameras axis, fine for x and y but I need z to be on the world axis, I’ve tried building a new cframe using ToWorldAxis() to get z but that just breaks x and y.

its been 5h please help
https://gyazo.com/38612516b2feae232d803ed9cfb3b29c

uis.MouseBehavior = Enum.MouseBehavior.LockCenter
local Delta = uis:GetMouseDelta()
					
local NewCF = CFrame.fromOrientation(math.rad(-Delta.Y/2),math.rad(-Delta.X/2),0)--math.rad(-Delta.X/2))
local finalcf = NewCF * CFrame.fromOrientation(NewCF.Y, NewCF.X, 0)
cc.CFrame = cc.CFrame * NewCF
1 Like

Hold on, lemme hop on the studio, ill send the math there like in 3 mins

1 Like

stuff from my own camera controller

Adjust it for your own needs

		local mouseDelta = uis:GetMouseDelta()
		
		self.DeltaX -= mouseDelta.X
		self.DeltaY = math.clamp(self.DeltaY - mouseDelta.Y, -80, 80)

		local pos = self.Target.Position

		self.Current = self.Current:Lerp(Vector2.new(self.DeltaX, self.DeltaY), deltaTime * self.RotationSpeed)
		local nextOrientation = CFrame.fromOrientation(self.Current.Y/mult, self.Current.X/mult, 0)
		self.Camera.CFrame = CFrame.new(pos) * nextOrientation
1 Like

Having a tad bit of trouble getting it to work, what was self referenced as here? I dont know (and can’t think of) the prerequisites

just imagine them as local variables in your case, this code used for my module script
self.DeltaX and self.DeltaY are self explanatory.
self.Target its the BasePart my camera follows, in my case its Character’s Head, you could just use your’s camera position instead.
self.Current its the current rotational values

I’ve used all my brainpower failing, I know this is easy but

mouseDelta.X -= mouseDelta.X

throws X cannot be assigned to, I assume I’m doing this wrong but can you point me in the right direction? also current would be a cframe’s rot which I dont think I can lerp with vector2s

This is how supposed to look like

local DeltaX = 0
DeltaX -= mouse.DeltaX

Ah I see, was a little confused there however now, like I said I’m unable to lerp a vector2 to cframe “Unable to cast Vector2 to CoordinateFrame”

Its the Vector2 that contains DeltaX and DeltaY, im lerping them for smooth rotation.
Please, read code carefully.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.