Mouse Lock does not work when i change the camera subject

I’m working on a personal project with a combat theme, to create a better visual effect during some of the attacks, I tried to change the camera subject to the character’s head, and it worked, more or less, the truth is that from then on, the character no longer rotates with the camera and is just directed to the direction it was before changing the subject, I wanted to fix it but continue with the default Lock, I just have no idea how.

1 Like

Are you looking for this?

Nop, as you can see, it stills not rotates the character when i change the camera subject to the head, as you can see here:

Try set

Humanoid.AutoRotate = true

Still not working :thinking:, gonna look deeper into It

When you changed the camera subject to the character’s head, the character no longer rotates with the camera, which is causing some issues. To fix this, you will need to update the character’s orientation to match the camera’s orientation.

-- Find the camera and character objects
local camera = game.Workspace.CurrentCamera
local character = game.Players.LocalPlayer.Character

-- Set the camera's CFrame to the character's head position and orientation
camera.CameraSubject = character.Head
camera.CFrame = character.Head.CFrame * CFrame.new(0, 0, -5) -- change the -5 value to adjust the camera distance from the character's head

-- Update the character's orientation to match the camera's orientation
character.Humanoid.AutoRotate = false -- turn off auto-orientation
character:SetPrimaryPartCFrame(camera.CFrame + Vector3.new(0, 0, 5)) -- change the 5 value to match the camera distance from the character's head

This code sets the camera’s CameraSubject to the character’s Head, and sets the camera’s CFrame to be positioned behind the character’s head. It then turns off the character’s auto-orientation, and updates the character’s orientation to match the camera’s orientation.

Note that this code is just a starting point, and you may need to modify it to fit your specific needs.

2 Likes

It’s pretty simple actually, you just have to make sure the camera type is custom and the camera subject is the humanoid. Most people often make the mistake that it is the head or the humanoid root part.