Mryeetmemes

Roblox 2D Game Camera Script

Nov 6th, 2021
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.02 KB | None | 0 0
  1. lockCamera = false
  2.     distance = 30
  3.     height = 5
  4.  
  5. local torso = script.Parent.Torso
  6. local center = Instance.new("Part")
  7. center.Name = script.Parent.Name .. " Center"
  8. center.Transparency = 1
  9. center.CanCollide = false
  10. center.Size = Vector3.new(1,1,1)
  11. center.Position = torso.Position
  12. center.CFrame = CFrame.new(Vector3.new(0,0,0),Vector3.new(0,0,-1))
  13. center.Parent = game.Workspace
  14. local bp = Instance.new("BodyPosition")
  15. bp.position = center.Position
  16. bp.maxForce = Vector3.new(1000000, 1000000, 1000000)
  17. bp.Parent = center
  18. local bg = Instance.new("BodyGyro")
  19. bg.maxTorque = Vector3.new(9e+005, 9e+005, 9e+005)
  20. bg.cframe = center.CFrame
  21. bg.Parent = center
  22. local cam = game.Workspace.CurrentCamera
  23. cam.CameraSubject = center
  24. cam.CameraType = Enum.CameraType.Attach
  25.  
  26. while torso.Parent do
  27.     wait()
  28.     center.BodyPosition.position = torso.Position
  29.     if lockCamera then
  30.         cam.CoordinateFrame = CFrame.new(Vector3.new(center.Position.x + distance,center.Position.y + height,center.Position.z))
  31.     end
  32. end
  33.  
  34. center:Remove()
  35.  
Advertisement
Add Comment
Please, Sign In to add comment