Make first person camera be in head's position

I recently created a script that makes the upper torso move up and down according to the camera’s direction. It works great but the problem is that the camera itself doesn’t follow the head’s position when looking up or down, this causes it to look very weird when looking high up or down.

Is there a way to keep the camera’s position the same as the head’s without needing to create my own first person camera? the camera is already set to LockFirstPerson.

2 Likes

If you are using inverse kinematics you need to connect the head to the look direction not the torso

I’m modifying the waist Motor6D to achieve the effect:

local cam = workspace.CurrentCamera
local plr = game.Players.LocalPlayer
local RunService = game:GetService("RunService")

local char = plr.Character or plr.CharacterAdded:Wait()
local upperTorso = char:WaitForChild("UpperTorso")

local waist = upperTorso:WaitForChild("Waist")

local y = waist.C0.Y

RunService.RenderStepped:Connect(function()
	if waist then
		local camDirection = cam.CFrame.LookVector
		local angle = math.deg(camDirection:Angle(char:WaitForChild("HumanoidRootPart").CFrame.LookVector, cam.CFrame.RightVector))
		waist.C0 = waist.C0:Lerp((CFrame.new(0, y, 0) * CFrame.Angles(math.rad(math.clamp(-angle, -70, 70)),0,0)), 0.5/2)
		
	end
end)
1 Like

If you go into a seperate view from the client is the head with the torso when you look down or does it stay in place?

1 Like

it moves with the torso, my problem isnt the head but that any attempts to set the camera’s cframe to the head causes it to spin violently.

1 Like

is the cameratype scriptable? I presume it is since this is an entire fps framework

1 Like

No, i just have it to LockFirstPerson

1 Like

Change it to scriptable and then set the camera’s cframe to the head

1 Like

nothing changes, it still spazzes out

1 Like

does it atleast follow the character

1 Like

Something i found while trying this: setting the cameraSubject to the head solves the spazzing issue, but now i cant rotate the camera and character around

2 Likes

it follows the character, but i cant tell if it on the head or not because of the spazzing

2 Likes

Found one:

char.Humanoid.CameraOffset = (char:WaitForChild("HumanoidRootPart").CFrame + Vector3.new(0, 1.5, 0)):PointToObjectSpace(char:WaitForChild("Head").Position)

This converts the head’s position from world space to the HRP’s object space, which is the same space that the CameraOffset uses, and sets the resulting position as the offset, putting the camera where the head is.

No spazzing and the controls work as normal now.

7 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.