I need help with camera rotation

I’m trying to make a GUI where camera in viewportframe rotates around the model while looking down at it from a 45 degree angle.

Everything works, except the 45 degree top down view.
This is my code:

RS:BindToRenderStep("RotateCam", Enum.RenderPriority.Camera.Value, function(Tick)
			rotation +=  SPEED * Tick
			local rot = CFrame.Angles(0, math.rad(rotation), 0)
			Camera.CFrame = CFrame.new(utils.LookAt(Camera, Cloned, 90, Vector3.new(0, 2, 0)).Position) * rot
		end)

This is the utils.LookAt function:

function utils.LookAt(Camera: Camera, Object: Model, FOV: number?, Offset: Vector3?): (CFrame, CFrame)
	local isModel = Object:IsA("Model") or Object:IsA("Tool")
	local CF: CFrame = (isModel and Object:GetPivot()) or Object.CFrame
	local Pos = CF.Position + (Offset or Vector3.new())
	local Size: Vector3 = (isModel and Object:GetExtentsSize()) or Object.Size
	local halfSize = Size.Magnitude / 2 + (FOV and FOV / 25 or 0)
	local fovDivisor = math.tan(math.rad(Camera.FieldOfView / 2))
	local Offset = halfSize / fovDivisor
	local Rotation = Camera.CFrame - Camera.CFrame.Position
	return Rotation + Pos + (-Rotation.LookVector * Offset), Rotation + Pos
end

If I change the CFrame.Angles thing to this: local rot = CFrame.Angles(0, math.rad(rotation), math.rad(-45) it looks very weird while rotating.

Any help appreciated.

3 Likes
Camera.CFrame = CFrame.new(Cloned.Position) * CFrame.Angles(0, math.rad(rotation), math.rad(-45)) * CFrame.new(Vector3.new(0,-5,0))
1 Like

It still rotates weirdly.

This is how it should rotate over the part looking at the part the whole time:
blender_9clHQRhwOU

And this is how it rotates when I add * CFrame.Angles(0, 0, math.rad(-45)):
blender_lxhmmAk9Yv

Hope this explains my problem better.

1 Like

Then

Camera.CFrame = CFrame.new(Cloned.Position) * CFrame.Angles(0, math.rad(rotation), math.rad(45)) * CFrame.new(Vector3.new(0,5,0))
1 Like

It doesn’t work. Its somewhere off screen now.

Camera.CFrame = CFrame.new(Cloned.Position) * CFrame.Angles(0, math.rad(rotation), 0) * CFrame.Angles(math.rad(-45), 0, 0) * CFrame.new(Vector3.new(0,0,15))

Its the same code you just provided in your last response…

Camera.CFrame = CFrame.new(Cloned.Position) * CFrame.Angles(0, math.rad(rotation), 0) * CFrame.Angles(math.rad(-45), 0, 0) * CFrame.new(Vector3.new(0,0,15))
2 Likes

you just increased the offset… This wont work.

Say that its not working after you test it…

Bro I’m impressed, it works!
Sorry for doubting you.

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