How to create a 3rd person over the shoulder camera script

I want to achieve a camera system similar to that of jailbreak when you equip a gun.

I have been researching this for about 2 days now, I have tried setting the cameras cframe, as well as humanoid.CameraOffset. However, none of these have worked, and the cframe sort of worked, however it didn’t have the zoom in and out feature.

If anyone could help me or point me in the right direction, that would be deeply appreciated!

Note: I have check roblox’s “Manipulating the camera” however, that did not work for my needs, as no zooming feature. Also, when I say zooming, I mean like being able to use the scroll wheel like in jailbreak, also when you zoom al the way in it puts you in first person.

4 Likes
local run = game:GetService("RunService")
local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local head = character:WaitForChild("Head")

local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable

while true do
	run.RenderStepped:Wait()
	camera.CFrame = head.CFrame * CFrame.new(-1, 2, 4)
end
1 Like

this is what i have so far

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local hrp = char:WaitForChild("HumanoidRootPart")
local human = char:WaitForChild("Humanoid")
local camera = workspace.CurrentCamera
local runService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
human.AutoRotate = false

runService.RenderStepped:Connect(function()
	camera.CameraType = Enum.CameraType.Scriptable
	UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
	local lookAtPos = (hrp.CFrame * CFrame.new(0,0,-10)).Position
	local cameraStartPos = (hrp.CFrame *  CFrame.new(1.5,2,5)).Position
	camera.CFrame = CFrame.lookAt(cameraStartPos,lookAtPos)
end)
1 Like

I used this in my old games.

-- player stuff
local plr = game.Players.LocalPlayer
local Char = plr.Character
local Cam = workspace.CurrentCamera
local HumanoidRootPart = Char:FindFirstChild("HumanoidRootPart")
-- camera action

local angle_x = 0
local cameraPos = Vector3.new(2.8,1.1,9)

Cam.CameraType = Enum.CameraType.Scriptable
UIS.MouseBehavior = Enum.MouseBehavior.LockCenter

CAS:BindAction("CameraMovement", function(_,_,input)
	angle_x = angle_x - input.Delta.x*0.4
end, false, Enum.UserInputType.MouseMovement)

RS.RenderStepped:Connect(function()
	if Char and HumanoidRootPart then
		UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
		local startCFrame = CFrame.new((HumanoidRootPart.CFrame.p + Vector3.new(0,2,0))) * CFrame.Angles(0, math.rad(angle_x), 0)
		local cameraCFrame = startCFrame + startCFrame:VectorToWorldSpace(Vector3.new(cameraPos.X, cameraPos.Y, cameraPos.Z))
		local cameraFocus = startCFrame + startCFrame:VectorToWorldSpace(Vector3.new(cameraPos.X, cameraPos.Y, -100000))
		Cam.CFrame = CFrame.new(cameraCFrame.p, cameraFocus.p)
		HumanoidRootPart.CFrame = CFrame.new(HumanoidRootPart.CFrame.p, HumanoidRootPart.CFrame.p + Vector3.new(Cam.CFrame.LookVector.X, 0, Cam.CFrame.LookVector.Z))
	end
end)

Also please define “RS” and “CAS” and “UIS”
RS is RunService, CAS is ContextActionService, and UIS is UserInputService

2 Likes

this is really good, however ive already tried this kind of thing before, and the only thing its missing is zooming in and out(‘zooming’ as in making the camera go further or closer to the player, and when fully zoomed goes to first person)

It’s easy to make a switch from third person to first person. You can easily change the offset and you can unlock the third person and use the normal camera.

yes but want to be abled to zoom in and out as shown:

nvm i got it:

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local human = char:WaitForChild("Humanoid")
local UIS = game:GetService("UserInputService")
local default = UserSettings().GameSettings
local runService = game:GetService("RunService")
local last = nil
local lastFirstPerson = false
local camera = workspace.CurrentCamera
local offset = 2.5

runService.RenderStepped:Connect(function()
	if lastFirstPerson ~= ((char.Head.Position - camera.CoordinateFrame.p).magnitude <= 0.5+offset) then
		lastFirstPerson = ((char.Head.Position - camera.CoordinateFrame.p).magnitude <= 0.5+offset)
		human.CameraOffset = (last and not lastFirstPerson)  and Vector3.new(offset,0,0) or Vector3.new(0,0,0)
	end
	if last == _G.ForceShiftLock then
		return
	end
	last = _G.ForceShiftLock
	UIS.MouseBehavior = last and Enum.MouseBehavior.LockCenter or Enum.MouseBehavior.Default
	default.RotationType = last and Enum.RotationType.CameraRelative or Enum.RotationType.MovementRelative
	human.CameraOffset = last and Vector3.new(offset,0,0) or Vector3.new(0,0,0)
end)

and have player module and this in starter player scripts

10 Likes