Navarone19_CH

Compass GUI

Jul 19th, 2020
3,703
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. local smoothness = 30/3
  2.  
  3. wait(1)
  4.  
  5. local player = game.Players.LocalPlayer
  6. local camera = workspace.CurrentCamera
  7.  
  8. local dev = script.Parent
  9.  
  10. local lastY = 0
  11. local units = {
  12. [dev.N ] = -math.pi * 4/4;
  13. [dev.NE] = -math.pi * 3/4;
  14. [dev.E ] = -math.pi * 2/4;
  15. [dev.SE] = -math.pi * 1/4;
  16. [dev.S ] = math.pi * 0/4;
  17. [dev.SW] = math.pi * 1/4;
  18. [dev.W ] = math.pi * 2/4;
  19. [dev.NW] = math.pi * 3/4;
  20. }
  21.  
  22. function restrictAngle(angle)
  23. if angle < -math.pi then
  24. return angle + math.pi*2
  25. elseif angle > math.pi then
  26. return angle - math.pi*2
  27. else
  28. return angle
  29. end
  30. end
  31.  
  32. while true do
  33. local delta = wait(1/30)
  34.  
  35. local look = camera.CoordinateFrame.lookVector
  36. local look = Vector3.new(look.x, 0, look.z).unit
  37. local lookY = math.atan2(look.z, look.x)
  38.  
  39. local difY = restrictAngle(lookY - lastY)
  40. lookY = restrictAngle(lastY + difY*delta*smoothness)
  41. lastY = lookY
  42.  
  43. for unit, rot in pairs(units) do
  44. rot = restrictAngle(lookY - rot)
  45. if math.sin(rot) > 0 then
  46. local cosRot = math.cos(rot)
  47. local cosRot2 = cosRot*cosRot
  48.  
  49. unit.Visible = true
  50. unit.Position = UDim2.new(0.5 + cosRot*0.6, unit.Position.X.Offset, 0, 3)
  51. else
  52. unit.Visible = false
  53. end
  54. end
  55. end
Add Comment
Please, Sign In to add comment