How can I create a 3rd person camera system

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    So as I am currently creating a game I think the 3rd person kinda camera would be really nice in this situation.
    Currently I have no idea how to make this, I’ve tried looking at some other posts but none of them really work, either that or they only support PC.
    Now I do actually have some code already. But it doesnt support Mobile or console, im not exactly sure how to do it. Id have to figure out how to tell where when the players swipes to the side or up on mobile or whatever and move it into place, and for console something with the joystick thingy. Ofc I dont know how to do any of those things. So if you could help me learn how I can do that, it would be very helpful! Thanks!
--|| SERVICES ||--
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")
--|| VARIABLES ||--
local Camera = workspace.Camera
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRootPart = Character:WaitForChild("HumanoidRootPart")
local CameraAngleX, CameraAngleY = 0,0
local CameraCFrame,CameraFocus,StartCFrame
local CameraOffset = Vector3.new(1,3,9.5)
local Movement = Enum.UserInputType.MouseMovement
RunService.RenderStepped:Connect(function()
	if Camera.CameraType ~= Enum.CameraType.Scriptable then
		Camera.CameraType = Enum.CameraType.Scriptable
	end
	StartCFrame = CFrame.new((HumanoidRootPart.CFrame.Position)) * CFrame.Angles(0, math.rad(CameraAngleX), 0) *  CFrame.Angles(math.rad(CameraAngleY), 0, 0)
	CameraCFrame = StartCFrame:ToWorldSpace(CFrame.new(CameraOffset.X, CameraOffset.Y, CameraOffset.Z))
	CameraFocus = StartCFrame:ToWorldSpace(CFrame.new(CameraOffset.X, CameraOffset.Y, -10000))
	Camera.CFrame = CFrame.new(CameraCFrame.Position, CameraFocus.Position)


	--|| Rotating the Character with mouse ||--
	--HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.Position) * CFrame.Angles(0, math.rad(CameraAngleX), 0)
end)
UserInputService.InputBegan:Connect(function(InputObject)
	local UserInputType = InputObject.UserInputType
	if UserInputService.MouseBehavior ~= Enum.MouseBehavior.LockCenter then
		UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
	end
end)
UserInputService.InputChanged:Connect(function(InputOject)
	local UserInputType= InputOject.UserInputType
	if(UserInputType== Movement)then
		local Delta = InputOject.Delta
		CameraAngleX = CameraAngleX-Delta.X
		CameraAngleY = math.clamp(CameraAngleY-Delta.Y, -75, 75)
	end
end)

I actually created a 3rd person camera system a few months ago without utilizing touch inputs - and it still works on mobile. It’s a very simple method. All I used was :GetMouseDelta(). Here is the code so you can view it yourself:

-- Services
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")

-- Settings
local Camera = workspace.CurrentCamera
local Offset = CFrame.new(2, 0, 0) -- Offset from the default camera's position

-- Main
RunService.RenderStepped:Connect(function(DT)
	local MouseDelta = UserInputService:GetMouseDelta()
	Camera.CFrame = CFrame.lookAt(Camera.CFrame.Position, Camera.CFrame * CFrame.new(MouseDelta.X, -MouseDelta.Y, -20000).Position) * Offset
end)

The good thing about this is that it’s basically Roblox’s default camera with an offset (you’re still able to zoom in, out, rotate, etc…). Don’t know if that’s something you would want though. Here’s a video of me testing it on mobile (it’s implemented into a gun system but the code I provided is the 3rd person camera aspect):

1 Like