Same camera script acts weird? Why?

So I have a script that makes the players camera point towards there mouse, in one game it works, in another it spins out of control.

How it should be:

local connect = run.RenderStepped:Connect(function()
	local np = Vector2.new(mouse.X,mouse.Y)
	local center = Vector2.new(camera.ViewportSize.X/2, camera.ViewportSize.Y/2)
	local difference = np - center
	
	local outcome = Vector2.new(difference.Y/center.Y, (difference.X/center.X)*maxDegree)
	
	camera.CFrame = CFrame.Angles(-outcome.X, -outcome.Y,0) + mainPart.Position
end)
How it is in my other game:

run.RenderStepped:Connect(function()
	local mp = Vector2.new(mouse.X, mouse.Y)
	local centre = Vector2.new(camera.ViewportSize.X/2, camera.ViewportSize.Y/2)
	local difference = mp - centre

	local outcome = Vector2.new((difference.Y/centre.Y)*maxDegree, (difference.X/centre.X)*maxDegree)
	camera.CFrame = CFrame.Angles(-outcome.X, -outcome.Y,0) + cameraPart.Position
end)

Thanks!

1 Like

Figured it out. the maxDegree value was supposed to be a math.rad

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