Advertisement
GForcebit

TopdownScript

Apr 29th, 2018
396
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. --Original Creator: jobro13
  2. repeat wait(1/60) until game.Players.LocalPlayer.Character and game.Workspace.CurrentCamera
  3. repeat wait(1/60) until game.Players.LocalPlayer.Character:FindFirstChild("Torso")
  4.  
  5. local Camera = game.Workspace.CurrentCamera
  6. local Torso = game.Players.LocalPlayer.Character.Torso
  7. Camera.CameraType = "Scriptable"
  8. Camera.CameraSubject = nil
  9.  
  10. repeat wait() until game.Players.LocalPlayer:FindFirstChild("PlayerGui")
  11.  
  12. local Player = game.Players.LocalPlayer
  13. local size = Instance.new("ScreenGui", Player.PlayerGui)
  14. size.Name = "Size"
  15.  
  16. local TMaxHeight = 200
  17. local TMinHeight = 10
  18. local TStep = 2.5
  19. local THeight = 10
  20.  
  21. local Keys = {}
  22.  
  23. local Mouse = Player:GetMouse()
  24. local mouse = Mouse
  25.  
  26. local dir = 0
  27.  
  28. -- USED KEYS SO FAR
  29. -- E,Q,R,X
  30.  
  31. local Keys = {}
  32.  
  33. local Locked = false
  34. local MouseTrack = false
  35.  
  36. function GetRotation(Unit)
  37.  
  38. --// Cosine in radian circle: y/x so angle alpha is cos-1(y/x) x=1
  39. --// Problem here is the circle itself as they have 2 solutions.
  40. local AbZ, AbX = math.abs(Unit.z), math.abs(Unit.x)
  41. local Real = math.atan(AbX/AbZ)
  42. --// ^ugly, super, super, ugly...
  43. --// Now find the quadrant
  44. local Plus = 0
  45. --// Cases are Z and X
  46. if Unit.z >= 0 and Unit.x >= 0 then
  47. --Plus = 0
  48. elseif Unit.z >= 0 and Unit.x < 0 then
  49. Plus = (0.5 * math.pi)
  50. Real = ((math.pi *1.5) - Real)
  51. elseif Unit.z < 0 and Unit.x < 0 then
  52. Plus = math.pi
  53. elseif Unit.z < 0 and Unit.x >= 0 then
  54. Plus = math.pi * 1.5
  55. Real = ((math.pi * 1.5) - Real)
  56. end
  57. return Real + Plus
  58. end
  59.  
  60. function Update()
  61. if not Locked and not Button2Down then
  62. if Keys["e"] then -- turn right
  63. dir = dir + 1
  64. end
  65. if Keys["q"] then -- turn left
  66. dir = dir - 1
  67. end
  68. if Keys["x"] then
  69. dir = math.deg(GetRotation(Torso.CFrame.lookVector)) - 90
  70. end
  71. end
  72. if not Button2Down then
  73. if not Locked and not MouseTrack then
  74.  
  75. elseif MouseTrack then
  76. local Size = Player.PlayerGui.Size.AbsoluteSize.X / 2
  77. local Pos = mouse.X
  78. local Diff = 0
  79. if math.abs(Size - Pos) > Size / 20 then
  80. local this = ((Size - Pos) / (Size))
  81. local mul = (this < 0 and -1) or 1
  82. Diff = math.sqrt(math.abs(this)) * 3 * mul
  83. end
  84. dir = dir + Diff
  85. else
  86. dir = math.deg(GetRotation(Torso.CFrame.lookVector)) - 90
  87. end
  88. end
  89. local rot = math.rad(dir)
  90. local x = -math.cos(rot)
  91. local z = math.sin(rot)
  92. local New = Vector3.new(x,0,z) / 1000
  93. local this = (mouse.hit.p - Torso.Position ).unit
  94. Camera.CoordinateFrame = CFrame.new(Vector3.new(Torso.Position.x, Torso.Position.y + THeight, Torso.Position.z) + New , Torso.Position)
  95. Camera:SetRoll(math.rad(dir))
  96. end
  97.  
  98.  
  99. game:GetService("RunService").RenderStepped:connect(function()
  100. Update()
  101. end)
  102.  
  103. function Zoom(TStep)
  104. THeight = ((THeight + TStep <= TMaxHeight and THeight + TStep >= TMinHeight) and THeight + TStep) or THeight
  105. end
  106.  
  107. mouse.WheelBackward:connect(function()
  108. Zoom(TStep)
  109. end)
  110.  
  111. mouse.WheelForward:connect(function() Zoom(-TStep) end)
  112.  
  113. mouse.KeyDown:connect(function(key)
  114. if key == "r" then
  115. Locked = not Locked
  116. if Locked then
  117. MouseTrack = false
  118. end
  119. elseif key == "f" then
  120. MouseTrack = not MouseTrack
  121. if MouseTrack then
  122. Locked = false
  123. end
  124. end
  125. Keys[key] = true
  126. end)
  127. mouse.KeyUp:connect(function(key)
  128. Keys[key] = false
  129. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement