How do I make the player's camera position so that it is fully in third person?

So I am making a script where people can click F and change between two camera modes, First and Third. The problem is that when the person switches back from First to Third, they have to zoom out manually to be fully in third person. Anyone know how I can fix it so that it automatically zooms the camera out into fully third person mode?

Code:

local Players = game:GetService("Players")
local plr = Players.LocalPlayer
local UIS = game:GetService("UserInputService")

local tps = true

UIS.InputBegan:Connect(function(input, gameProcessed)
   if not gameProcessed then
       if input.UserInputType == Enum.UserInputType.Keyboard then
           if input.KeyCode == Enum.KeyCode.F then
               if tps then
                   plr.CameraMode = Enum.CameraMode.LockFirstPerson
                   tps = false
               else
                   plr.CameraMode = Enum.CameraMode.Classic
                   tps = true
               end
           end
       end
   end
end)

Note: This is my first ever post so please do understand if I made some mistakes, Thanks!

1 Like

Offset the camera CFrame in the z axis.

local length = 5;
camera.CFrame = camera.CFrame * CFrame.new(0,0,-length);
1 Like

First of all, please organize your code. It’s basically un-readable in this state. Second, there are quite a few tutorials for this on the dev forum. Please do research before coming here to post. This should be your last resort.

Which camera, the one inside workspace or offset the one inside the humanoid?

There is only one camera local to the player. You can point to it by typing the following code in a LOCAL script.

local rbxCamera = workspace.CurrentCamera;
local Players = game:GetService("Players")
local plr = Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local rbxCamera = game.Workspace.CurrentCamera
local length = 5

local tps = true

UIS.InputBegan:Connect(function(input, gameProcessed)
    if not gameProcessed then
            if input.KeyCode == Enum.KeyCode.F then
                if tps then
                    plr.CameraMode = Enum.CameraMode.LockFirstPerson
                    tps = false
                else
                    plr.CameraMode = Enum.CameraMode.Classic
                    rbxCamera.CFrame = rbxCamera.CFrame * CFrame.new(0,0,-length)
                    tps = true
                end
            end
    end
end)

It did not do anything

hey, this isn’t a solution to your problem but quick tip:

you can do tps = not tps regardless if it’s true or false, it will always change it to the opposite boolean. for example, you can change tps = false with tps = not tps to tps = true and same happens vice versa.

Thanks! However do u know the solution?

are you trying to change the FOV or something?

Its because you need to set the camera to scriptable first, cframe it, then set it to classic

Yes, i guess so? Im not excetly sure what FOV is actually.

scrap that, FOV is a property that when it is manipulated, it changes your Field of View and changes how you see things from your camera.

No, im trying to make it so that the camera automatically gets zoomed out of first person mode when a player switches to third person instead of having to scroll/zoom out manually.

local Players = game:GetService("Players")
local plr = Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local rbxCamera = game.Workspace.CurrentCamera
local length = 5

local tps = true

UIS.InputBegan:Connect(function(input, gameProcessed)
    if not gameProcessed then
            if input.KeyCode == Enum.KeyCode.F then
                if tps then
                    plr.CameraMode = Enum.CameraMode.LockFirstPerson
                    tps = false
                else
                    plr.CameraMode = Enum.CameraMode.Scriptable
                    rbxCamera.CFrame = rbxCamera.CFrame * CFrame.new(0,0,-length)
                    plr.CameraMode = Enum.CameraMode.Classic
                    tps = true
                end
            end
    end
end)

I’ve proposed to you a solution. FOV has nothing to do with anything related to this post. Its simply how much of the world you can view from your camera

That’s actually not true at all. It’s indented, and the variables are finely named.

I have found a solution to my problem. What you can do is change the CameraMinZoomDistance to your desire distance and quickly change it back to the default(0.5).

1 Like

That was before he fixed it…

Edit: It looked like this before:

local Players = game:GetService(“Players”)
local plr = Players.LocalPlayer
local UIS = game:GetService(“UserInputService”)

local tps = true

UIS.InputBegan:Connect(function(input, gameProcessed)
if not gameProcessed then
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.F then
if tps then
plr.CameraMode = Enum.CameraMode.LockFirstPerson
tps = false
else
plr.CameraMode = Enum.CameraMode.Classic
tps = true
end
end
end
end
end)

1 Like

Okay. But it’d be nice to actually tell them how to fix it instead of just critiquing how bad it is.

2 Likes

I agree with Sharper, like I said, I am new to posting topics so please underatand the mistakes. However I have already edited and fixed it.

1 Like