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)
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