So I want to rotate a player’s camera based on them controlling how much to rotate on the x, y, and z axis. However, let’s say a player’s camera is at -15,0,0 (orientation) and they want to increment the y axis of the camera by 1 to be -15,1,0. This doesn’t do that, it increments y AND z by a small value.
My code is here: (essentially, it’s just a way for players to record scenes for their YouTube videos easier in Roblox studio)
Controls are this image:
local function updateCamera(posOrRot,axis,value)
if posOrRot=="Position" then
if axis == "X" then
workspace.CurrentCamera.CFrame=CFrame.new(value,workspace.CurrentCamera.CFrame.Position.Y,workspace.CurrentCamera.CFrame.Position.Z)
mainFrame.positionFrame.positionOptions.xPositionButtonController.Frame.TextBox.Text = math.round(value*1000)/1000
elseif axis == "Y" then
workspace.CurrentCamera.CFrame=CFrame.new(workspace.CurrentCamera.CFrame.Position.X,value,workspace.CurrentCamera.CFrame.Position.Z)
mainFrame.positionFrame.positionOptions.yPositionButtonController.Frame.TextBox.Text = math.round(value*1000)/1000
else
workspace.CurrentCamera.CFrame=CFrame.new(workspace.CurrentCamera.CFrame.Position.X,workspace.CurrentCamera.CFrame.Position.Y,value)
mainFrame.positionFrame.positionOptions.zPositionButtonController.Frame.TextBox.Text = math.round(value*1000)/1000
end
workspace.CurrentCamera.CFrame*=CFrame.fromOrientation(math.rad(allScenes[currentSelectedFilmId][currentSelectedScene]["Animations"][currentAnimationSelected]["Orientation"].X),math.rad(allScenes[currentSelectedFilmId][currentSelectedScene]["Animations"][currentAnimationSelected]["Orientation"].Y),math.rad(allScenes[currentSelectedFilmId][currentSelectedScene]["Animations"][currentAnimationSelected]["Orientation"].Z))
elseif posOrRot == "Orientation" then
local xOrientation,yOrientation,zOrientation = workspace.Camera.CFrame:ToEulerAnglesXYZ()
local pos = workspace.CurrentCamera.CFrame.Position
local rot = workspace.CurrentCamera.CFrame - pos
if axis == "X" then
--workspace.CurrentCamera.CFrame*=CFrame.fromOrientation(math.rad(value)-xOrientation,0,0)
rot = CFrame.fromAxisAngle(Vector3.new(1,0,0),math.rad(value)-xOrientation) * rot
workspace.CurrentCamera.CFrame = rot + pos
mainFrame.orientationFrame.orientationOptions.xOrientationButtonController.Frame.TextBox.Text = math.round(value*1000)/1000
elseif axis == "Y" then
--workspace.CurrentCamera.CFrame*=CFrame.fromOrientation(0,math.rad(value)-yOrientation,0)
--workspace.CurrentCamera.CFrame*=CFrame.fromAxisAngle(Vector3.new(0,1,0),math.rad(value)-yOrientation)
rot = CFrame.fromAxisAngle(Vector3.new(0,1,0),math.rad(value)-yOrientation) * rot
workspace.CurrentCamera.CFrame = rot + pos
mainFrame.orientationFrame.orientationOptions.yOrientationButtonController.Frame.TextBox.Text = math.round(value*1000)/1000
else
workspace.CurrentCamera.CFrame*=CFrame.fromOrientation(0,0,math.rad(value)-zOrientation)
mainFrame.orientationFrame.orientationOptions.zOrientationButtonController.Frame.TextBox.Text = math.round(value*1000)/1000
end
else
end
end
Any help helps! Thanks!
