Yea I found what I was looking for. So many views and not even an upvote or a comment. Thx anyways
local workspaceService = game:GetService("Workspace")
local runService = game:GetService("RunService")
local playersService = game:GetService("Players")
local userInputService = game:GetService("UserInputService")
local SENSITIVITY = 0.4
local WORLD_OFFSET = Vector3.new(0, 2, 0)
local LOCAL_OFFSET = Vector3.new(3, 0, 9.5)
local camera = workspaceService.CurrentCamera
local localPlayer = playersService.LocalPlayer
local xAngle = 0
local yAngle = 0
userInputService.InputChanged:Connect(function(input, isProcessed)
if isProcessed then return end
if input.UserInputType ~= Enum.UserInputType.MouseMovement then return end
local delta = input.Delta
local deltaX = delta.X
local deltaY = delta.Y
xAngle = xAngle - deltaX * SENSITIVITY
yAngle = math.clamp(yAngle - deltaY * SENSITIVITY, -80, 80)
end)
runService:BindToRenderStep("CameraUpdate", Enum.RenderPriority.Camera.Value, function()
local cameraSubject = camera.CameraSubject
if not cameraSubject then return end
local isLocalPlayer = false
local subject
local ignoredInstance
if cameraSubject:IsA("Humanoid") then
ignoredInstance = cameraSubject.Parent
if not ignoredInstance:IsA("Model") then return end
subject = ignoredInstance.PrimaryPart
if not subject then return end
if localPlayer.Character == ignoredInstance and cameraSubject.Health > 0 then
isLocalPlayer = true
end
elseif cameraSubject:IsA("BasePart") then
subject = cameraSubject
ignoredInstance = cameraSubject
else return end
local xAngleCFrame = CFrame.Angles(0, math.rad(xAngle), 0)
local anglesCFrame = xAngleCFrame:ToWorldSpace(CFrame.Angles(math.rad(yAngle), 0, 0))
local cameraPosition = subject.Position + WORLD_OFFSET
local startCFrame = CFrame.new(cameraPosition):ToWorldSpace(anglesCFrame)
local cameraCFrame = startCFrame:ToWorldSpace(CFrame.new(LOCAL_OFFSET))
local cameraFocus = cameraCFrame:ToWorldSpace(CFrame.new(0, 0, -LOCAL_OFFSET.Z))
camera.Focus = cameraFocus
camera.CFrame = cameraCFrame
camera.CFrame = cameraCFrame:ToWorldSpace(CFrame.new(0, 0, -camera:GetLargestCutoffDistance({ignoredInstance})))
if isLocalPlayer then
local primaryPartCFrame = ignoredInstance:GetPrimaryPartCFrame()
local newCFrame = CFrame.new(primaryPartCFrame.Position):ToWorldSpace(xAngleCFrame)
end
end)
userInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
1 comment
:I