Help with custom Camera script

  1. What do you want to achieve?
    I’m trying to achieve a fully custom camera script.

  2. What is the issue?
    I got the first person camera working but the character doesn’t rotate along with it.
    I tried changing Camera.Focus I also tried setting UserGameSettings.RotationType to CameraRelative
    and it still didn’t work. I was looking at how the default scripts do it and I tried doing it the way they do, but it still didn’t work! I tried printing the value of the focus they set and the one I set and it was the same, but when I did it, the character didn’t follow the camera.

  3. What solutions have you tried so far? I say the solutions I tried in the above question.

Here is my code:

RunService.RenderStepped:Connect(function()
	UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
	UserGameSettings.RotationType = Enum.RotationType.CameraRelative
	
	moveFunction(game.Players.LocalPlayer,Vector3.new(moveMent.r+moveMent.l,0,moveMent.b+moveMent.f),true) -- Control Movement
	
	local subPos = GetSubjectPosition()
	local newCameraFocus = CFrame.new(subPos)
	local cameraFocusP = newCameraFocus.p
	
	local newLookVector = CalculateNewLookCFrame().LookVector
	rotateInput = Vector2.new(0,0)
	Camera.CFrame = CFrame.new(cameraFocusP - (5 * newLookVector), cameraFocusP)
	Camera.Focus = newCameraFocus -- Doesn't work even tho it's the same as the default roblox one :/
end)

Hey.
If you’re trying to set the player’s camera to first person view, how about setting CameraMode to LockFirstPerson. Like so:

game.Players.LocalPlayer.CameraMode = Enum.CameraMode.LockFirstPerson

It’s already on LockFirstPerson, what I meant is, you know how the character rotates with the camera while in first person. I’m trying to achieve that with a custom camera script, but it’s not working.

If you’ve set the CameraType to Scriptable then UGS.RotationType will not have have an effect, neither will “LockFirstPerson”.

It’s a little hard to help you debug this without knowing what “CalculateNewLookCFrame().LookVector” does. My guess is that you’re not providing the Camera.CFrame property with the CFrame of the Character, and are instead passing a Vec3. If so, then yes, you will lose all rotational information related to the Character.

1 Like

CameraType is set to Custom, CalculateNewLookCFrame doesn’t control the Camera Focus only the CFrame

function GetSubjectPosition()
	local cameraSubject = Camera and Camera.CameraSubject

	return cameraSubject.CFrame.p
end

local subPos = GetSubjectPosition()
local newCameraFocus = CFrame.new(subPos)

Camera.Focus = newCameraFocus

Also, I confirmed this is the way it’s done in the default camera scripts and commenting the line in the default scripts also stops the character from rotating

If you want to rotate the character manually you can do this in the Render Step:

local camera = workspace.CurrentCamera
local hrp = HumanoidRootPart —Grab this from the character
hrp.CFrame = CFrame.new(hrp.Position,hrp.Position + camera.CFrame.LookVector * Vector3.new(1,0,1))

Sorry if it’s messed up I’m on mobile.

1 Like

Thank you works perfectly.

30charswhy

1 Like