Advertisement
HowToRoblox

ShoulderCamHandler

Sep 5th, 2020 (edited)
6,817
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.21 KB | None | 0 0
  1. local uis = game:GetService("UserInputService")
  2.  
  3.  
  4. local camera = workspace.CurrentCamera
  5. camera.CameraType = Enum.CameraType.Scriptable
  6.  
  7.  
  8. local char = script.Parent
  9.  
  10. local humanoid = char:WaitForChild("Humanoid")
  11. humanoid.AutoRotate = false
  12.  
  13. local hrp = char:WaitForChild("HumanoidRootPart")
  14.  
  15.  
  16. local x = 0
  17. local y = 0
  18.  
  19.  
  20. local offset = Vector3.new(3, 3, 10)
  21.  
  22.  
  23. uis.InputChanged:Connect(function(input, processed)
  24.    
  25.     if processed then return end
  26.    
  27.     if input.UserInputType == Enum.UserInputType.MouseMovement then
  28.        
  29.         x = x - input.Delta.X
  30.        
  31.         y = math.clamp(y - input.Delta.Y*0.4, -75, 75)
  32.        
  33.        
  34.         hrp.CFrame = hrp.CFrame * CFrame.Angles(0, math.rad(-input.Delta.X), 0)
  35.     end
  36. end)
  37.  
  38.  
  39. game:GetService("RunService").RenderStepped:Connect(function()
  40.    
  41.     uis.MouseBehavior = Enum.MouseBehavior.LockCenter
  42.    
  43.    
  44.     local startCFrame = CFrame.new((hrp.CFrame.Position)) * CFrame.Angles(0, math.rad(x), 0) * CFrame.Angles(math.rad(y), 0, 0)
  45.     local cameraCFrame = startCFrame:ToWorldSpace(CFrame.new(offset.X, offset.Y, offset.Z))
  46.     local cameraDirection = startCFrame:ToWorldSpace(CFrame.new(offset.X, offset.Y, -10000))
  47.    
  48.     camera.CFrame = CFrame.new(cameraCFrame.Position, cameraDirection.Position)
  49. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement