Advertisement
AlphaHacker2001

MoonFix[Maybe]

Dec 16th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. lp=game.Players.LocalPlayer
  2. local Tool = Instance.new('HopperBin',lp.Backpack)
  3. Tool.Name='MoveMoon'
  4.  
  5. -- convert number (in hours) to TimeOfDay string
  6. -- because TimeOfDay doesn't cast numbers as expected (3.42 -> 03:42:00 instead of 3:07:00)
  7. local function ToTimeOfDay(n)
  8. n = n % 24
  9. local i,f = math.modf(n)
  10. local m = f*60
  11. local mi,mf = math.modf(m)
  12. m = tostring(math.abs(math.floor(m)))
  13. local s = tostring(math.abs(math.floor(mf*60)))
  14. return i..":"..string.rep("0",2-#m)..m..":"..string.rep("0",2-#s)..s
  15. end
  16.  
  17. -- convert TimeOfDay string to number (in hours)
  18. local function FromTimeOfDay(t)
  19. local signed,h,m,s = t:match("^(%-?)(%d+):(%d+):(%d+)$")
  20. s = tonumber(s)/60
  21. m = tonumber(m + s)/60
  22. h = tonumber(h) + m
  23. return h * (#signed > 0 and -1 or 1)
  24. end
  25.  
  26. local function rad_sc(n)
  27. return n/(math.pi*2)
  28. end
  29.  
  30. local function sc_rad(n)
  31. return n*(math.pi*2)
  32. end
  33.  
  34. -- convert direction to latitude (as GeographicLatitude) and longitude (as TimeOfDay)
  35. local function ToLatLon(d)
  36. d = Vector3.new(-d.x,-d.y,d.z) -- derp derp derp derp derp
  37. local lat = math.atan2(d.z,math.sqrt(d.x^2 + d.y^2))
  38. local lon = math.atan2(d.y,d.x)
  39.  
  40. lat = rad_sc(lat)*360 + 23.5
  41. lon = ToTimeOfDay(rad_sc(lon)*24 - 6)
  42.  
  43. return lat,lon
  44. end
  45.  
  46. --[[
  47. -- convert lat and lon to direction (doesn't work)
  48. local function to_dir(lat,lon)
  49. lat = sc_rad((lat - 23.5)/360)
  50. lon = sc_rad((FromTimeOfDay(lon) + 6)/24)
  51.  
  52. return Vector3.new(
  53. (math.cos(lat)*math.cos(lon)),
  54. (math.cos(lat)*math.sin(lon)),
  55. math.sin(lat)
  56. )
  57. end
  58. ]]
  59.  
  60. local Event = {}
  61. local function Disconnect(...)
  62. for _,name in pairs{...} do
  63. if Event[name] then
  64. Event[name]:disconnect()
  65. Event[name] = nil
  66. end
  67. end
  68. end
  69.  
  70. local Lighting = Game:GetService("Lighting")
  71. local down = false
  72.  
  73. local P = 0.02
  74. local D = 16
  75. local position = Lighting:GetMoonDirection()
  76. local velocity = Vector3.new(0,0,0)
  77. local goal = Lighting:GetMoonDirection()
  78.  
  79. local active = false
  80. local function Activate(Mouse)
  81. position = Lighting:GetMoonDirection()
  82. goal = Lighting:GetMoonDirection()
  83. active = true
  84. Event.Down = Mouse.Button1Down:connect(function()
  85. down = true
  86. goal = Mouse.UnitRay.Direction
  87. end)
  88.  
  89. Event.Up = Mouse.Button1Up:connect(function()
  90. down = false
  91. end)
  92.  
  93. Event.Move = Mouse.Move:connect(function()
  94. if down then
  95. goal = Mouse.UnitRay.Direction
  96. end
  97. end)
  98.  
  99. asd = game:GetService'RunService'.RenderStepped:connect(function()
  100. velocity = Vector3.new(
  101. velocity.x + P * ((goal.x - position.x) + D * -velocity.x),
  102. velocity.y + P * ((goal.y - position.y) + D * -velocity.y),
  103. velocity.z + P * ((goal.z - position.z) + D * -velocity.z)
  104. )
  105. position = position + velocity
  106. local lat,lon = ToLatLon(position)
  107. Lighting.GeographicLatitude = lat
  108. Lighting.TimeOfDay = lon
  109. --print(lon)
  110. --wait()
  111. end)
  112. end
  113.  
  114. local function Deactivate()
  115. active = false
  116. down = false
  117. asd:disconnect()
  118. Disconnect("Down","Up","Move")
  119. end
  120.  
  121. Tool.Selected:connect(Activate)
  122. Tool.Deselected:connect(Deactivate)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement