How to Make a Player's Camera Face a Certain Direction?

How do I make the player’s camera be facing the same way that the character itself if facing? For my obby, players are spawned in at a checkpoint and their character will have the same orientation as the checkpoint (note that the checkpoint is a BasePart and not a SpawnLocation!). However, even though their character’s orientation is the same as the checkpoint, the camera does not move to behind the player when the character’s orientation has been changed.

So basically, I want the camera to be behind the player when they spawn in, but I want the players to still be able to freely move around their camera after they’ve spawned in.

Any help is greatly appreciated!

2 Likes

You can add this in the StarterCharacterScripts:

local Run = game:GetService("RunService")
local Character = game.Players.LocalPlayer.Character

Run.RenderStepped:Connect(function()
  local CharCF = Character.PrimaryPart.CFrame
  local CamLook = workspace.CurrentCamera.CFrame.LookVector *100
  Character:SetPrimaryPartCFrame(CharCF.p,Vector3.new(CamLook.X,CharCF.p.Y,CamLook.Z)

end)

Hope this helps! :grinning_face_with_smiling_eyes:

1 Like

That script does nothing and just keeps producing errors.

Thanks anyways.

If anyone could tell me how to solve this problem I’d be very grateful!

This could work:

local Character = script.Parent
local Camera = workspace.CurrentCamera
local RunService = game:GetService("RunService")

Camera.CameraSubject = Character.Head
Camera.CameraType = Enum.CameraType.Attach

local function OnUpdate()
	if Character and Character:FindFirstChild("Humanoid") then
		Camera.CFrame = CFrame.new(Character.Head.Position) * CFrame.new(0,0,10)
	end
end

RunService:BindToRenderStep("Camera",Enum.RenderPriority.Camera.Value, OnUpdate)

Try a adding LocalScript to StarterCharacterScripts & put this code inside of it:

wait()
workspace.CurrentCamera.CameraType = Enum.CameraType.Scriptable
workspace.CurrentCamera.CFrame = CFrame.new(workspace.CurrentCamera.CFrame.Position,script.Parent:WaitForChild("HumanoidRootPart").CFrame.LookVector)
workspace.CurrentCamera.CameraType = Enum.CameraType.Custom

What this will do is it checks the HumanoidRootPart’s direction its looking & apply the same to the camera.
for example if it’s looking directly at Z+, then the camera’s LookVector will be 0,0,1

I haven’t tested this so if anything doesn’t work, try adding .Unit after the LookVector on the third line

This changes the camera position but it does not change it to be behind the player.

Please dont use wait(), you can just do

local character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
-- code

To wait for the character to load in.

1 Like