Is there a way to detect the position of your camera whilst in third person?

I want to implement a thing that disables actions inside a tool when in third person, How can I detect if a player is in first person or third person?

1 Like

So the main way you do this is by checking the distance of the camera from the head (by comparing their positions and finding the difference).

I’ve found a number that is pretty reliable for me, so I’ll share that with you (shown in the script, 1.5).

NOTE: This can only be done in a local script because you need to check the camera’s position in accordance to the camera. You can technically use a remote event to send updates to the server about the camera’s position, but that would spam the remote and would cause errors and throttling by ROBLOX.

local Camera = workspace.CurrentCamera
local Character = script.Parent -- This is assuming that the script is inside of the character/startercharacterscripts, update as needed

Camera:GetPropertyChangedSignal("Focus"):Connect(function()
	local Distance = (Camera.CFrame.Position - script.Parent:GetPivot().Position).Magnitude
	
	if Distance >= 1.5 then
		-- This is when you are in third person
		
	else
		-- First person
	end
end)

If you want further explanations, I can give them. I am writing most of this assuming that you know a thing or two. I hope this assists you in developing your project!

2 Likes

if everyone is wondering, this is the only way to check for third person/ first person camera

1 Like

I meant more in the execution of the way that I did it. Some people prefer using RunService instead of GetPropertyChangedSignal (because of different functions, like having to update something every frame instead of just every time the camera changes in some way).

Would it spam if you had the distance check only fire the remote if the distance switched from higher to lower (or lower to higher) than 1.5 studs?
If the player was constantly zooming the camera then maybe it’d spam, but you could also do

if Distance < 1.2 then
    -- first person
elseif Distance > 1.8 then
    -- 3rd person
end

to create a small ‘dead zone’ so if the camera was set at 1.5 studs and moved back and forth between 1.499 and 1.501 studs during gameplay.

Maybe print the distance every time the Focus function fires to see how often the actual distance changes.
If it’s firing because Distance is changing by .00001 studs then round Distance to 1 decimal place and run the rest of the code with that value.

What I’m saying is if you are constantly firing the event then it’ll be a problem. You can’t really fire an event that many times by zooming honestly.

I mean I guess this could work but it’s not super important for what he’s doing to my knowledge.

As said before the usual way people seem to do it is to check the distance between the camera and the player’s head.

I do the same, but I also make use of the LocalTransparencyModifier:

which as far as I understand only comes into play when the player is zoomed into first person, or near first person such that their body parts become semi-transparent.
Grab the head, check its LTM, and if it’s at 0 that should mean the player is in third person. At 1 should be first person (or maybe at 0 is first person and 1 is third person, I haven’t touched the code in many months).