Problem with my custom orbital camera

Recently I started making tons of multiplayer games and got interested by some Top-Down Camera shooters. As I was trying to recreate it, I wanted it to be like the roblox Orbital camera control. Here’s the code provided:

local Player = game.Players.LocalPlayer
local Camera = game.Workspace.CurrentCamera
local RunService = game:GetService("RunService")
local StarterPlayer = game:GetService("StarterPlayer")

local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local Humanoid = Character:WaitForChild("Humanoid")

RunService.RenderStepped:Connect(function(Step)
	
	Camera.CameraType = Enum.CameraType.Custom

	local LookVector = Camera.CFrame.LookVector
	
	HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.Position) * CFrame.Angles(0,math.atan2(-LookVector.X,-LookVector.Z) ,0)
	
	Camera.CFrame = Camera.CFrame:Lerp(CFrame.new(HumanoidRootPart.Position) * CFrame.Angles( 0, math.atan2(-LookVector.X,-LookVector.Z), 0), 0.1 )

end)

Now, this kind of does what I want, however, instead of going from top to bottom, it looks like a Third Person Shooter Camera with the Y Axis disabled.

So yeah, I also tried putting numbers and math.rad() in the CFrame.Angles, it just makes the camera very glitchy lol. Any help would be appreciated.

2 Likes

math.atan2(x,y) doesn’t return the degrees you need, you must convert it by dividing by / math.pi

Odd, because it works perfectly fine, I can rotate the camera on the X and Z Axis perfectly fine. The only problem is that I want the camera to face from top to bottom.

Camera.CFrame = CFrame.new(A:Vector3,B:Vector3)
Should be fine (A is up, B is down)

That is the most basic, I’m using lerp however, I want a top down camera that can rotate the X and the Z, that’s why I used Math.Atan()

After you set the Camera.CFrame, try resetting it again to look at player.

RunService.RenderStepped:Connect(function(Step)
	Camera.CameraType = Enum.CameraType.Custom
	local LookVector = Camera.CFrame.LookVector
	HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.Position) * CFrame.Angles(0,math.atan2(-LookVector.X,-LookVector.Z) ,0)
	Camera.CFrame = Camera.CFrame:Lerp(CFrame.new(HumanoidRootPart.Position) * CFrame.Angles( 0, math.atan2(-LookVector.X,-LookVector.Z), 0), 0.1 )	
	--make camera look at player
	Camera.CFrame = CFrame.new(Camera.CFrame.Position, HumanoidRootPart.Position)
end)
1 Like

okay thank you, I will try that later.

1 Like