Advertisement
memesbruh03

custom camera compatible for minipeeps

Aug 26th, 2016
389
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.85 KB | None | 0 0
  1. local sp = script.Parent
  2.  
  3.  
  4. local player = game.Players.LocalPlayer
  5. local runService = game:GetService('RunService')
  6. local cam = game.Workspace.CurrentCamera
  7.  
  8.  
  9. local p = game.Workspace:FindFirstChild('CameraPart') or Instance.new('Part')
  10. p.Name = 'CameraPart'
  11. p.TopSurface = 'Smooth'
  12. p.BottomSurface = 'Smooth'
  13. p.FrontSurface = 'Hinge'
  14. p.Anchored = true
  15. p.CanCollide = false
  16. p.Parent = game.Workspace
  17.  
  18.  
  19. local stickyness = 0.01
  20. local desiredHeight = 5
  21. local desiredDist = 25
  22. local maxDist = 2
  23. local minDist = 0
  24.  
  25.  
  26. local function swait(a)
  27.     if a and a>.0333 then
  28.         wait(a)
  29.     else
  30.         runService.RenderStepped:wait()
  31.     end
  32. end
  33.  
  34.  
  35. while true do
  36.     swait()
  37.     local character = player.Character
  38.     if character and character.Parent == game.Workspace then
  39.         local target = character:FindFirstChild('Torso')
  40.         if target then
  41.             cam.CameraType = 'Scriptable'
  42.             local vectorAway = ((cam.CoordinateFrame.p - target.Position) * Vector3.new(1,0,1)).unit
  43.             if vectorAway.x ~= vectorAway.x then
  44.                 vectorAway = Vector3.new(1,0,0)
  45.             end
  46.             local desiredPos = target.Position + vectorAway * desiredDist + Vector3.new(0,desiredHeight,0)
  47.             local resultPos = desiredPos * stickyness + cam.CoordinateFrame.p * (1-stickyness)
  48.             local resultVec = resultPos - target.Position
  49.             local resultUnitVec = (resultVec).unit
  50.             if resultUnitVec.x ~= resultUnitVec.x then
  51.                 resultUnitVec = Vector3.new(1,0,0)
  52.             end
  53.             local gotClamped = false
  54.             if resultVec.magnitude > maxDist then
  55.                 resultVec = resultUnitVec * maxDist
  56.                 gotClamped = true
  57.             elseif resultVec.magnitude < minDist then
  58.                 resultVec = resultUnitVec * minDist
  59.                 gotClamped = true
  60.             end
  61.  
  62.             if gotClamped then
  63.                 cam.CoordinateFrame = CFrame.new(target.Position+resultVec,target.Position)
  64.             else
  65.                 cam.CoordinateFrame = CFrame.new(resultPos,target.Position)
  66.             end
  67.         end
  68.     end
  69. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement