First Person Camera with camera subject set to head!

Hello I was experimenting with some scripts, and I wanted to make the camera follow the head instead of the character. When I zoom into first person it becomes all glitchy.

1 Like

Can you please share your code?

local plr = game:GetService("Players").LocalPlayer
local camera = workspace.CurrentCamera
local char = plr.CharacterAdded:Wait()
local hum = char:WaitForChild("Humanoid")

camera.CameraSubject = char:WaitForChild("Head")

Where is your script parented? And are there any errors?

It’s a local script in Starter Player > StarterCharacterScripts

It doesn’t seem to glitch for me. Are there any other scripts that use the camera that could be interfering?

I used this for first person:

local lPlr = game.Players.LocalPlayer
if lPlr then
	wait()
	lPlr.CameraMode = 0
	lPlr.CameraMode = 1
end
script:Destroy()

Setting your CameraSubject to the player’s head messes up some first person checks in the camera module, as it expects the subject to be a Humanoid.

Here’s a snippet from my own game that might give you the effect you want:

local Offset = Vector3.new()
RunService.RenderStepped:Connect(function (DeltaTime)
		Offset = Offset:Lerp((HumanoidRootPart.CFrame + Vector3.new(0, 1.5, 0)):PointToObjectSpace(Head.Position), DeltaTime * 20)
		Humanoid.CameraOffset = Offset
end)

Is this script in Starter Player < StarterCharacterScripts?

This didn’t do anything for me, I didn’t get any errors either.

Copy the default PlayerModule that you find when you launch the game in the player scripts and place it in PlayerStarterScripts. Find the TransparencyController and go to line 130.

function TransparencyController:SetSubject(subject)
	local character = nil
	if subject and subject:IsA("Humanoid") then
		character = subject.Parent
	end
	if subject and subject:IsA("VehicleSeat") and subject.Occupant then
		character = subject.Occupant.Parent
	end
	if character then
		self:SetupTransparency(character)
	else
		self:TeardownTransparency()
	end
end

When you set the subject to anything but the humanoid this block fails to run, so you have to add an additional line that considers the head so something like

function TransparencyController:SetSubject(subject)
	local character = nil
	if subject and subject:IsA("Humanoid") or subject and subject.Name == "Head"  then
		character = subject.Parent
	end
	if subject and subject:IsA("VehicleSeat") and subject.Occupant then
		character = subject.Occupant.Parent
	end
	if character then
		self:SetupTransparency(character)
	else
		self:TeardownTransparency()
	end
end

They both look the same so setting the subject to the head is only worth when it’s in third person, the character rotation is also still broken after setting the subject so the best thing to do is set the offset on a renderstep and go from there.

4 Likes

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