Top-Down to First-Person

Hello, I’m new here… Wanted to ask how to make a good camera that can switch from top-down to First Person

So here’s the current code I have so far:

--D6D--
wait()
while not game.Players.LocalPlayer.Character:FindFirstChild('HumanoidRootPart') do wait() end

local cam = workspace.CurrentCamera
--cam.CameraType = 'Custom'
cam.CameraType = 'Scriptable'


local RunService = game:GetService('RunService')

while RunService.Stepped:wait() do

	local head = game.Players.LocalPlayer.Character:FindFirstChild('HumanoidRootPart')
	local distanceX = script.DistanceFromHeadX.Value
	local distanceY = script.DistanceFromHeadY.Value
	local distanceZ = script.DistanceFromHeadZ.Value

	cam.CoordinateFrame = CFrame.new(Vector3.new(head.Position.x + distanceX, head.Position.y + distanceY, head.Position.Z + distanceZ),head.Position)

end

is it possible to just go from cam.CameraType = ‘Scriptable’ to cam.CameraType = ‘Custom’ ? like, somehow stop RunService.Stepped ?

any type of help would be awesome.

would a connect function work?

--D6D--
wait()
while not game.Players.LocalPlayer.Character:FindFirstChild('HumanoidRootPart') do wait() end

local cam = workspace.CurrentCamera
--cam.CameraType = 'Custom'
cam.CameraType = 'Scriptable'


local RunService = game:GetService('RunService')

game:GetService("UserInputService").InputBegan:connect(function(input, Processed)
    if not Processed then
        if input.KeyCode == Enum.KeyCode.C then
            if cam.CameraType == 'Scriptable' then
                cam.CameraType = 'Custom'
            else
                cam.Cameratype = 'Scriptable'
            end
        end
    end
end)

while RunService.Stepped:wait() do

	local head = game.Players.LocalPlayer.Character:FindFirstChild('HumanoidRootPart')
	local distanceX = script.DistanceFromHeadX.Value
	local distanceY = script.DistanceFromHeadY.Value
	local distanceZ = script.DistanceFromHeadZ.Value

	cam.CoordinateFrame = CFrame.new(Vector3.new(head.Position.x + distanceX, head.Position.y + distanceY, head.Position.Z + distanceZ),head.Position)

end
1 Like

it gives me this weird error "Cameratype is not a valid member of Camera “Workspace.Camera” , let me try and fix it wait

ok I fixed the error it was just that you put Cameratype instead of CameraType

didn’t work, camera doesn’t change at all

I made a script that does change from Scriptable to Custom, now I just need a way to unlock the camera, since its constantly looking at the player cuz of

while RunService.Stepped:wait() do

	local head = game.Players.LocalPlayer.Character:FindFirstChild('HumanoidRootPart')
	local distanceX = script.DistanceFromHeadX.Value
	local distanceY = script.DistanceFromHeadY.Value
	local distanceZ = script.DistanceFromHeadZ.Value

	cam.CoordinateFrame = CFrame.new(Vector3.new(head.Position.x + distanceX, head.Position.y + distanceY, head.Position.Z + distanceZ),head.Position)

end

code for the camera that changes from scriptable to custom:

local playerC = game.Players.LocalPlayer.Character
local playerL = game.Players.LocalPlayer
local mouse = game.Players.LocalPlayer:GetMouse()

local distanceX = playerL.PlayerGui.CameraScript.DistanceFromHeadX.Value
local distanceY = playerL.PlayerGui.CameraScript.DistanceFromHeadY.Value
local distanceZ = playerL.PlayerGui.CameraScript.DistanceFromHeadZ.Value

local running = false
local click = false

function getTool()	
	for _, kid in ipairs(script.Parent:GetChildren()) do
		if kid.className == "Tool" then return kid end
	end
	return nil
end



mouse.KeyDown:connect(function (key) -- Run function
	key = string.lower(key)

	if string.byte(key) == 112 then
		if click then
			--disable
			running = false
			
			cam.CameraType = 'Scriptable'

			
			click = false

			wait()
		else
			--enable
			wait()
			
			click = true
			cam.CameraType = 'Custom'
			

			running = true

			

			wait()
		end
	end
end)

Use UserInputService, also edited some of your code.

local RunService = game:GetService('RunService')
local UserInputService = game:GetService('UserInputService')

local player = game.Players.LocalPlayer

if not player.Character then
    player.CharacterAdded:Wait()
end

while not player.Character:FindFirstChild('HumanoidRootPart') do
    RunService.Stepped:Wait()
end

local cam = workspace.CurrentCamera
local toggled = false

UserInputService.InputBegan:Connect(function(input)
    if input.KeyCode ~= Enum.KeyCode.F then
       return
    end

    if toggled then
        cam.CameraType = 'Custom'
        toggled = false
    else
        cam.CameraType = 'Scriptable'
        toggled = true
    end
end)

RunService.Stepped:Connect(function()
    if not toggled then
        return
    end

	local head = player.Character:FindFirstChild('HumanoidRootPart')
	local distanceX = script.DistanceFromHeadX.Value
	local distanceY = script.DistanceFromHeadY.Value
	local distanceZ = script.DistanceFromHeadZ.Value

	cam.CFrame = CFrame.new(Vector3.new(head.Position.x + distanceX, head.Position.y + distanceY, head.Position.Z + distanceZ),head.Position)

end)
1 Like

well this works splendidly if pressing the KeyCode !, only small little problem is when the player spawns the camera seems to be looking at the void, ill fix it and come back at you with the fixed code!, give me a bit.

1 Like

Should be noted that when working with the camera you should use RenderStepped, not Stepped

2 Likes

camera gets stuck when player spawns, but after pressing the keycode it works just fine, im guessing the RunService.RenderStepped isnt starting when the player spawns

Forgot to change the cameratype property changing at the beginning.

CameraType seems to do nothing about it?, even if I start the camera as Scriptable

Cuz like I said, RunService doesnt seem to start running once the player spawns in

changed it to RenderStepped, Thanks!

I wanted the script to stop the RunService.RenderStepped and then change the CameraType from Scriptable to Custom for example.

Well this is what worked for me!

local RunService = game:GetService('RunService')
local UserInputService = game:GetService('UserInputService')

local player = game.Players.LocalPlayer
local cam = workspace.CurrentCamera


if not player.Character then
	player.CharacterAdded:Wait()
end

while not player.Character:FindFirstChild('HumanoidRootPart') do
	RunService.RenderStepped:Wait()
end

local toggled = true

UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode ~= Enum.KeyCode.Q then
		return
	end

	if toggled then
		cam.CameraType = 'Custom'
		toggled = false
	else
		cam.CameraType = 'Scriptable'
		toggled = true
	end
end)

RunService.RenderStepped:Connect(function()
	if not toggled then
		return
	end

	local head = player.Character:FindFirstChild('HumanoidRootPart')
	local distanceX = script.DistanceFromHeadX.Value
	local distanceY = script.DistanceFromHeadY.Value
	local distanceZ = script.DistanceFromHeadZ.Value

	cam.CFrame = CFrame.new(Vector3.new(head.Position.x + distanceX, head.Position.y + distanceY, head.Position.Z + distanceZ),head.Position)

end)

Thank you a lot to everybody that replied!

if somebody asks for the camera I will make the Script and the other stuff into a nice Model so everybody can use it.

2 Likes