Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Custom orbital camera rotation?

Hey there fellas! I've this nice lil' script here for a custom orbital camera. The final thing I want it to do is a free fixed rotation sideways with Q and E buttons, but changing the values at CFrameAngles(5.5, 0, 0) -part makes the camera twisted and weird like this https://i.gyazo.com/027e8b46d903be4ec530edb834f21264.mp4

What would you suggest? Oh, and I don't have any mechanics for the camera rotation yet, just tried changing those values and noticed its a terrible way to work with.

local RunService = game:GetService("RunService")
local target = script.Parent:FindFirstChild("HumanoidRootPart")
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera.CameraSubject = target
local angle = 4
local newangle = 4


local function checkDelta(deltaTime)
    camera.CoordinateFrame = CFrame.new(target.Position)
                           * CFrame.Angles(5.5, 0, 0)
                           * CFrame.new(0, 0, 30)
end
RunService:BindToRenderStep("Check delta", Enum.RenderPriority.First.Value, checkDelta)

1 comment

0

I get an about:blank for the link- is it dead?

1 answer

✓ Accepted answer

You're using CFrame.Angles() the wrong way or in a way you overlooked.

By looking atCFrame's reference on CFrame.Angles you'll see that it takes in radians. On line 12, you're wanting to rotate the camera about 5.5 radians which is really 315 degrees.

It would look better, and save you the time, if you use the roblox function of math.rad to convert the radians into degrees.

local RunService = game:GetService("RunService")
local target = script.Parent:FindFirstChild("HumanoidRootPart")
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
camera.CameraSubject = target

local angle = 4 --??
local newangle = 4 --??

local desiredAngle = 45 --How you want the camera to be angled. You can also use this when the person inputs Q or E.

local function checkDelta(deltaTime)
	camera.CoordinateFrame = CFrame.new(target.Position)
                           * CFrame.Angles(math.rad(desiredAngle), 0, 0) -- Rotate camera by 45 deg
                           * CFrame.new(0, 0, 30)
end

--Since you're working with the camera and later using input to change it; leave this on the Camera Priority.
RunService:BindToRenderStep("Check delta", Enum.RenderPriority.Camera.Value, checkDelta)

Quick-Reference on CFrame is a good thing to have open when working with CFrame

1 comment

0

Sorry for the late answer, and thanks! This'll help me as I'll get back to studio.

This discussion is preserved as it was. New answers, comments, and votes are closed.