How to position players camera slighty infront of the head in first person

Im making a first person horror game and when you are in first person you can see the players neck.


One of the strategies I’ve thought of is to position the camera slightly in front of the head, so you wouldn’t see the neck.

This is the code I have got so far

while wait(0.1) do
	local camera = workspace.CurrentCamera

	if  (char.Head.CFrame.p - camera.CFrame.p).Magnitude < 1 then
	
	camera.CameraType = Enum.CameraType.Scriptable
		camera.CFrame = char.Head.CFrame + Vector3.new(1,0,0)
	end
end

But what ends up happening is the camera gets stuck in place when you go into first person.


Thanks for the help!

Change the Humanoid’s CameraOffset to the negative Z axis
Humanoid.CameraOffset

game:GetService("RunService").RenderStepped:Connect(function()
	if  (char.Head.CFrame.p - camera.CFrame.p).Magnitude < 1 then
		char:WaitForChild("Humanoid").CameraOffset = Vector3.new(0,0,-1)
    else
        char:WaitForChild("Humanoid").CameraOffset = Vector3.new(0,0,0)
	end
end)

How could I add it so while your running it would change? It is currently like this, you can still see the neck.
robloxapp-20221120-1914530.wmv (1.0 MB)

function IsFirstPerson()
	return (char.Head.CFrame.p - camera.CFrame.p).Magnitude < 1
end

game:GetService("RunService").RenderStepped:Connect(function()
	if  IsFirstPerson()  then
		char:WaitForChild("Humanoid").CameraOffset = Vector3.new(0,0,-1)
	else
		char:WaitForChild("Humanoid").CameraOffset = Vector3.new(0,0,0)
	end
end)

char:WaitForChild("Humanoid").Running:Connect(function(speed)
	if speed > 0 and IsFirstPerson() then
		char:WaitForChild("Humanoid").CameraOffset = Vector3.new(0,0,-2) -- 
	end
end)

I tried your script, and it starts flickering and you can see 2 torso’s. I tried to take a screenshot of it but the screenshot doesn’t show the issue.

Oh yeah, I forgot to tell you, I added first person hands using the LocalTransparencyModifier to get the players hands.

Actually I think what you should do is make the torso transparent using LocalTransparencyModifier as well

The game designer wants the torso to be visible though, like how doors accomplished it.

I think if you could just find a way to remove the flickering I could do the rest, I think its because of the animation, I was using ninja which tilts the torso forward

Here is what is happening, the torso flickers when you are looking at it.
robloxapp-20221120-1957384.wmv (2.3 MB)

From what i’ve noticed Doors uses a specific running animation where
the head is hiding and, in the video you just showed me, the running animation
makes the whole body exposed in first person.

To fix the flickering, I used TweenService where instead of it setting
the Camera instantly it transitions it.

local TweenService = game:GetService("TweenService")

function IsFirstPerson()
	return (char.Head.CFrame.p - camera.CFrame.p).Magnitude < 1
end

local Humanoid = char:WaitForChild("Humanoid")
local info = TweenInfo.new(5,Enum.EasingStyle.Linear,Enum.EasingDirection.In)

game:GetService("RunService").RenderStepped:Connect(function()
	if  IsFirstPerson()  then
		local Tween = TweenService:Create(Humanoid, info, {CameraOffset = Vector3.new(0,0,-1)})
		Tween:Play()
	else
		local Tween = TweenService:Create(Humanoid, info, {CameraOffset = Vector3.new(0,0,0)})
		Tween:Play()
	end
end)

char:WaitForChild("Humanoid").Running:Connect(function(speed)
	if speed > 0 and IsFirstPerson() then
		local Tween = TweenService:Create(Humanoid, info, {CameraOffset = Vector3.new(0,0,-2)})
		Tween:Play()
	end
end)

I hope this fixes the issue

1 Like

Thank you! This works like a charm! I just have to edit the values, thank you so much for the help though!

1 Like

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