First person camera following the head

I would like to have the player’s camera locked to the position and rotation of their character’s head in first person and still be able to use their mouse to turn and control their camera like normal first person.

Every time I try to lock the camera to the head using the cameratypes and changing the subject it makes it so I can’t control my camera/character with the mouse anymore.

I have tried a ton of different ways to do it, none of which have worked.

1 Like

Have you tried making it so that the camera follows the head ONLY whilst youre in first person - Using runservice and local transparency modifier - ?

Yes, my game will be first person only. I have knowledge of for loops and can get the body to show up, that isn’t an issue. When you are in first person, if you set the CFrame of the camera to the CFrame of the head (or a part welded to the head), when you move the mouse it no longer makes the character rotate. I apologize for the late reply.

Wait im super confused. Do you want the camera to follow the head, or the head to follow the xamera?

I want the camera to follow the head, so if the character rolls or slides the camera will follow both the location and rotation of the head. I am making a parkour system for a game, that is the reason I would like this.

You can maybe try attaching a motor6d from the camera to your head, but i dont know if it will work

–tbh im completely new–

Ah, well, thank you for attempting to help; I may just make it match the location but not the rotation, I guess. Since you’re new, if you need any help let me know.

wait before we finish, could i see your code?

Do you mean in a position where, say if you rolled with this camera locked onto the head, your camera would literally roll with you and possibly induce dizziness?

(Kind of like the realistic ragdoll simulator FPS optins you find)

You can just put the head instead of this newpart creating and stuff.

local centerHeadAttach: Attachment = script.Parent:WaitForChild("Head"):WaitForChild("FaceCenterAttachment")

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

local runServ = game:GetService("RunService")
local currentCamera = workspace.CurrentCamera

local newCameraPart = Instance.new("Part")
local newAttach = Instance.new("Attachment", newCameraPart)
local newPosAlign = Instance.new("AlignPosition", newCameraPart)
local newRotAlign = Instance.new("AlignOrientation", newCameraPart)
newPosAlign.RigidityEnabled = true
newPosAlign.ReactionForceEnabled = true
newPosAlign.ApplyAtCenterOfMass = true

newPosAlign.Attachment0 = newAttach
newRotAlign.Attachment0 = newAttach

newPosAlign.Attachment1 = centerHeadAttach
newRotAlign.Attachment1 = centerHeadAttach

newCameraPart.CanCollide = false
newCameraPart.Size = Vector3.new(0.5, 0.5, 0.5)
newCameraPart.CFrame = centerHeadAttach.WorldCFrame

newCameraPart.Parent = script.Parent

--currentCamera.CameraSubject = newCameraPart

currentCamera.CameraType = Enum.CameraType.Scriptable
runServ.RenderStepped:Connect(function(dt)
	currentCamera.CFrame = newCameraPart.CFrame
	currentCamera.CFrame = CFrame.lookAt(currentCamera.CFrame.Position, mouse.Hit.Position)
end)

Yes, exactly this. I have a working system right now, but it makes everything jitter when you walk backwards or sideways. I wouldn’t have any animations extreme enough to induce motion sickness though, and I will add a setting to disable it.

This does somewhat get the effect that I am looking for, but it makes the mouse not be locked while in first person, it also makes the character turn oddly while pressing A or D.

You could try this code:

-- Put in StarterCharacterScripts
local RunService = game:GetService("RunService")
local Workspace = game:GetService("Workspace")

local character = script.Parent
local head = character:WaitForChild("Head")  -- Pretty sure this is the name of the head part

local camera = Workspace.CurrentCamera

local function afterCamera(delta)
	-- TODO: Make sure the head cframe is where you want it
	-- i.e. use camera.CFrame to reposition the head properly
	-- e.g. head.CFrame = camera.CFrame - camera.Position + head.Position
	camera.CFrame = head.CFrame
end

RunService:BindToRenderStep("After camera", Enum.RenderPriority.Camera.Value + 1, afterCamera)

This will override the camera to the CFrame of the head. To have the camera still move you’ll still need to move the cframe of the head, but you can use the modified camera CFrame from the last update as shown in the code above. (Also make sure to have the camera set to first person in StarterCharacter or in the Player object.)

This is useful for capturing the default camera movement but not being locked into the exact position determined by the default camera.

This does technically put the camera in the right position, but it also makes you randomly turn as you’re walking. I’m not really sure how to do this properly. Thank you for the help so far though.

1 Like

I accidentally had a minus one instead of a plus one for the priority. The change might have fixed it, though I suspect the problem might be something different (you might need to make the movements character relative instead of camera relative, though I don’t recall the specifics of doing that).

Edit:

Here is how to make the character movement relative to something other than the camera. That should fix your problem if you have something in mind for it to move relative to.

(I also realize now this might not be what you meant by turning. Perhaps the fixed code will solve that problem.)

Thank you, I will test this and edit this reply when I know if it works.

edit 1:

What I mean by the turning and things is that it behaves like you’re in third person. It turns left while holding A and right while holding D. Another issue is that the mouse isn’t locked to the center of the screen, so you can only turn by using A or D.

1 Like

Did you make sure to set the camera to first person? It will look like first person either way but the camera movement behavior is inherited from the mode it’s in.

You can set the camera to first person by adding:

local player = game:GetService("Players"):GetPlayerFromCharacter(character)
player.CameraMaxZoomDistance = 0

So, making the movement relative to the character instead of the camera would be great, but the mouse no longer rotates the character (since it isn’t locked) so I wouldn’t be able to turn at all after spawning in.

Ah, sorry that was a stupid mistake. It now spins rapidly (because of the camera and the head creating a loop?) I’m not completely sure why. Even if I don’t move the mouse it will spin like crazy for every few seconds. Would it be better to just throw out the idea of making it follow the rotation? Should I make it only follow the position instead? Then main reason I even got into this whole camera positioning mess is because of my running animation, it makes the player lean forward a bit and if I just make the body visible the camera is too far back and too high.

I’m working on some code though it’s more difficult than I thought. I’ll see if I can get something working.