Changing Camera Rotation without Changing Position

I’m trying to remake the roblox studio camera for a game that I’m making, I have the movement working and the camera sorta working, when I use the camera it’s not right I cant really explain it but it looks very realistic and not like roblox studio’s camera. I can get the camera working normally but then the movement gets messed up because it changes the CFrame’s position and not just the rotation.

Try using the code and put the camera type to scriptable to see what I’m talking about.

If you can help with this issue that would be amazing,

Try using

CFrame.fromEulerAnglesXYZ

Method, not really intelligible on this matter, but try and give CFrame.fromEulerAnglesXYZ a shot.

I still run into the same problem, Have you tried re making the script in studio to see that problem?

Send the full code if you can.

– [[ Normal Varibels ]] –

local Player = game.Players.LocalPlayer
local Char = workspace:WaitForChild(Player.Name).Char
local Cam = game.Workspace.CurrentCamera

local Mouse = Player:GetMouse()
local Uis = game:GetService(“UserInputService”)
local Run = game:GetService(“RunService”)
local Ts = game:GetService(“TweenService”)

local CameraSettings = require(game.ReplicatedStorage.CameraSettings)

– [[ Constructure Varibels ]] –

local CAMERASPEED = CameraSettings.CameraMoveSpeed

– [[ Settings ]] –

Cam.CameraType = CameraSettings.CameraType
Cam.CFrame = CFrame.new(0,0,0)
Cam.CFrame = Char.CFrame

– [[ Camera Functionality ]] –

local W,A,S,D,NotMoving = false,false,false,false,true

–// Making Player Keep Moving

local function KeepMoving()

repeat
if W then
Cam.CFrame = Cam.CFrame + (Cam.CFrame.ZVector * -CAMERASPEED)

  end
  if 	S then 
  	Cam.CFrame = Cam.CFrame + (Cam.CFrame.ZVector * CAMERASPEED)
  	
  end
  if 	A then 
  	Cam.CFrame = Cam.CFrame + (Cam.CFrame.RightVector * -CAMERASPEED) 
  	
  end
  if 	D then 
  	

  	Cam.CFrame = Cam.CFrame + (Cam.CFrame.RightVector * CAMERASPEED) 
  end
  

  
  Char.CFrame = Cam.CFrame
  
  Run.RenderStepped:Wait()

until NotMoving

end

–// When Player Starts Moving

local function MoveBegan(actionName,inputState,input)

if input.UserInputType == Enum.UserInputType.Keyboard then

  if Uis:IsKeyDown(Enum.KeyCode.W) then
  	W = true
  	NotMoving= false
  end
  if Uis:IsKeyDown(Enum.KeyCode.A) then
  	A = true
  	NotMoving= false
  end
  if Uis:IsKeyDown(Enum.KeyCode.S) then
  	S = true
  	NotMoving= false
  end
  if Uis:IsKeyDown(Enum.KeyCode.D) then
  	D = true
  	NotMoving= false
  end

end

if W and not S and not D and not A then
KeepMoving()
elseif not W and not S and not D and A then
KeepMoving()
elseif not W and not S and not D and A then
KeepMoving()
elseif not W and not S and not D and A then
KeepMoving()
end

end

–// When Player Stops Moving

local function MoveEnded(input, gpe)

if input.KeyCode == Enum.KeyCode.W then
W = false
elseif input.KeyCode == Enum.KeyCode.S then
S = false
elseif input.KeyCode == Enum.KeyCode.D then
D = false
elseif input.KeyCode == Enum.KeyCode.A then
A = false
end
end

if not W and not S and not D and not A then
NotMoving = true
else
NotMoving = false
end

Uis.InputChanged:Connect(function(InputObject)

if InputObject.UserInputType == Enum.UserInputType.MouseMovement then

local LookAt = Vector3.new(-InputObject.Delta.Y / 300, -InputObject.Delta.X / 300, 0)

Cam.CFrame = Cam.CFrame * CFrame.fromEulerAngles(

  	LookAt.X,
  	LookAt.Y,
  	0	

)

end

end)

game:GetService(“ContextActionService”):BindAction(“MoveCam” , MoveBegan, false,Enum.KeyCode.W, Enum.KeyCode.A, Enum.KeyCode.S, Enum.KeyCode.D)
Uis.InputEnded:Connect(MoveEnded)

Mouse.Button2Down:Connect(function()

Uis.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition

end)

Mouse.Button2Up:Connect(function()

Uis.MouseBehavior = Enum.MouseBehavior.Default

end)

Put this in starter player scripts

Can you give the module script for CameraSettings?

I’m just useing a local script not a module script

It says require, so that means there is a module script.

oh that would be the camera settings but sure

This actually a problem I tackled while making my Studio camera, since CFrame.Angles is local, your camera gets rotated with the current rotation. You need to count out the current rotation from the equation.

Something like this:

local rx, ry, rz = Cam.CFrame:ToEulerAnglesYXZ()
		
local Angles: CFrame = CFrame.fromEulerAnglesYXZ(rx + LookAt.X,ry + LookAt.Y, rz)

Cam.CFrame *= Angles

EDIT: Realized this might not have been what you where looking for.

local Settings = {}

Settings.CameraMoveSpeed = 0.6

Settings.CameraLookSpeed = 0.01

Settings.CameraType = “Scriptable”

Settings.Xmin = -100

Settings.Ymin = -100

Settings.Zmin = -100

Settings.Xmax = 100

Settings.Ymax = 100

Settings.Zmax = 100

return Settings

I fixed everything.

Local Script:

local Player = game.Players.LocalPlayer
local Char = workspace:WaitForChild(Player.Name)
local Cam = game.Workspace.CurrentCamera

local Mouse = Player:GetMouse()
local Uis = game:GetService("UserInputService")
local Run = game:GetService("RunService")
local Ts = game:GetService("TweenService")

local CameraSettings = require(game.ReplicatedStorage.CameraSettings)



local CAMERASPEED = CameraSettings.CameraMoveSpeed



Cam.CameraType = CameraSettings.CameraType
Cam.CFrame = CFrame.new(0,0,0)
Cam.CFrame = Char:WaitForChild("HumanoidRootPart").CFrame



local W,A,S,D,NotMoving = false,false,false,false,true

local function KeepMoving()

	repeat
		if W then
			Cam.CFrame = Cam.CFrame + (Cam.CFrame.ZVector * -CAMERASPEED)

		end
		if 	S then 
			Cam.CFrame = Cam.CFrame + (Cam.CFrame.ZVector * CAMERASPEED)

		end
		if 	A then 
			Cam.CFrame = Cam.CFrame + (Cam.CFrame.RightVector * -CAMERASPEED) 

		end
		if 	D then 


			Cam.CFrame = Cam.CFrame + (Cam.CFrame.RightVector * CAMERASPEED) 
		end



		Char.CFrame = Cam.CFrame

		Run.RenderStepped:Wait()
	until NotMoving

end



local function MoveBegan(actionName,inputState,input)

	if input.UserInputType == Enum.UserInputType.Keyboard then

		if Uis:IsKeyDown(Enum.KeyCode.W) then
			W = true
			NotMoving= false
		end
		if Uis:IsKeyDown(Enum.KeyCode.A) then
			A = true
			NotMoving= false
		end
		if Uis:IsKeyDown(Enum.KeyCode.S) then
			S = true
			NotMoving= false
		end
		if Uis:IsKeyDown(Enum.KeyCode.D) then
			D = true
			NotMoving= false
		end
	end

	if W and not S and not D and not A then
		KeepMoving()
	elseif not W and not S and not D and A then
		KeepMoving()
	end

end

---

local function MoveEnded(input, gpe)

	if input.KeyCode == Enum.KeyCode.W then
		W = false
	elseif input.KeyCode == Enum.KeyCode.S then
		S = false
	elseif input.KeyCode == Enum.KeyCode.D then
		D = false
	elseif input.KeyCode == Enum.KeyCode.A then
		A = false
	end
end

if not W and not S and not D and not A then
	NotMoving = true
else
	NotMoving = false
end

Uis.InputChanged:Connect(function(InputObject)

	if InputObject.UserInputType == Enum.UserInputType.MouseMovement then

		local LookAt = Vector3.new(-InputObject.Delta.Y / 300, -InputObject.Delta.X / 300, 0)

		Cam.CFrame = Cam.CFrame * CFrame.fromEulerAngles(

			LookAt.X,
			LookAt.Y,
			0	
		)

	end

end)

game:GetService("ContextActionService"):BindAction("MoveCam" , MoveBegan, false,Enum.KeyCode.W, Enum.KeyCode.A, Enum.KeyCode.S, Enum.KeyCode.D)
Uis.InputEnded:Connect(MoveEnded)

Mouse.Button2Down:Connect(function()

	Uis.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition

end)

Mouse.Button2Up:Connect(function()

	Uis.MouseBehavior = Enum.MouseBehavior.Default

end)

Module Script:

local Settings = {}

Settings.CameraMoveSpeed = 0.6

Settings.CameraLookSpeed = 0.01

Settings.CameraType = Enum.CameraType.Scriptable

Settings.Xmin = -100

Settings.Ymin = -100

Settings.Zmin = -100

Settings.Xmax = 100

Settings.Ymax = 100

Settings.Zmax = 100

return Settings

well, I did not work, I fixed it because there is no humanoid or humanoidrootpart so I just change that to the character cframe, but there was nothing really wrong with all of that. It is just the camera

Do you see a lot of errors in the script? Try to fix those errors.

I could not tell if it was fixed because when I moved the camera it was way to fast to see anything, and I tried diving the look at by more then 300 but that did not change anything

I’ll send a video of it on my screen.

There is not errors, it’s fixed its just the camera is not like roblox studio’s camera

Is this how you intended it to work?

thats not how I wanted it to work. you can see how when you move the camera it gets tilted I just want it to stay flat if you know what I mean.

I know what you mean, but right now, I have no knowledge on how to fix this.