Is this what you’re looking for
Over-the-Shoulder
A basic over-the-shoulder camera, commonly found in third-person shooter games, can be achieved with the following script. This camera stays locked behind the character’s back and players use the mouse to turn (not directional input).
1. local Players = game:GetService("Players")
2. local ContextActionService = game:GetService("ContextActionService")
3. local UserInputService = game:GetService("UserInputService")
4. local RunService = game:GetService("RunService")
* local camera = workspace.CurrentCamera
5. local cameraOffset = Vector3.new(2, 2, 8)
6. local player = Players.LocalPlayer
* player.CharacterAdded:Connect(function(character)
* local humanoid = character:WaitForChild("Humanoid")
7. local rootPart = character:WaitForChild("HumanoidRootPart")
8. humanoid.AutoRotate = false
* local cameraAngleX = 0
9. local cameraAngleY = 0
* local function playerInput(actionName, inputState, inputObject)
10. -- Calculate camera/player rotation on input change
11. if inputState == Enum.UserInputState.Change then
12. cameraAngleX = cameraAngleX - inputObject.Delta.X
13. -- Reduce vertical mouse/touch sensitivity and clamp vertical axis
14. cameraAngleY = math.clamp(cameraAngleY-inputObject.Delta.Y*0.4, -75, 75)
15. -- Rotate root part CFrame by X delta
16. rootPart.CFrame = rootPart.CFrame * CFrame.Angles(0, math.rad(-inputObject.Delta.X), 0)
17. end
18. end
19. ContextActionService:BindAction("PlayerInput", playerInput, false, Enum.UserInputType.MouseMovement, Enum.UserInputType.Touch)
* RunService.RenderStepped:Connect(function()
20. if camera.CameraType ~= Enum.CameraType.Scriptable then
21. camera.CameraType = Enum.CameraType.Scriptable
22. end
23. local startCFrame = CFrame.new((rootPart.CFrame.Position)) * CFrame.Angles(0, math.rad(cameraAngleX), 0) * CFrame.Angles(math.rad(cameraAngleY), 0, 0)
24. local cameraCFrame = startCFrame:ToWorldSpace(CFrame.new(cameraOffset.X, cameraOffset.Y, cameraOffset.Z))
25. local cameraFocus = startCFrame:ToWorldSpace(CFrame.new(cameraOffset.X, cameraOffset.Y, -10000))
26. camera.CFrame = CFrame.new(cameraCFrame.Position, cameraFocus.Position)
27. end)
28. end)
* local function focusControl(actionName, inputState, inputObject)
29. -- Lock and hide mouse icon on input began
30. if inputState == Enum.UserInputState.Begin then
31. UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
32. UserInputService.MouseIconEnabled = false
33. ContextActionService:UnbindAction("FocusControl", focusControl, false, Enum.UserInputType.MouseButton1, Enum.UserInputType.Touch, Enum.UserInputType.Focus)
34. end
35. end
36. ContextActionService:BindAction("FocusControl", focusControl, false, Enum.UserInputType.MouseButton1, Enum.UserInputType.Touch, Enum.UserInputType.Focus)
Note the camera offset values on line 7 — these can be adjusted to change the camera’s relative position to the character, for example to place it over the character’s left shoulder ( -2, 2, 8
) or pull the camera further away from the player ( 2, 2, 15
).