Advertisement
BobMe

planet orbit-2d

Feb 9th, 2022
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.07 KB | None | 0 0
  1. local gravity = 0.01 -- earth gravity
  2. script.Name = "ORBYORB"..tostring(math.random(34,32764))
  3. local function AccurateWait(seconds)
  4. local RunService = game:GetService("RunService")
  5. if not seconds then
  6. seconds = 0
  7. end
  8. local last = tick()
  9. local secondsPassed = 0
  10. local connection = RunService.Heartbeat:Connect(function(dt)
  11. secondsPassed = secondsPassed + dt
  12. end)
  13. repeat
  14. RunService.Heartbeat:Wait()
  15. until secondsPassed >= seconds
  16. connection:Disconnect()
  17. end
  18. local function reverse_table(tab)
  19. local function deepCopy(original)
  20. local copy = {}
  21. for k, v in pairs(original) do
  22. if type(v) == "table" then
  23. v = deepCopy(v)
  24. end
  25. copy[k] = v
  26. end
  27. return copy
  28. end
  29. local t = deepCopy(tab)
  30. for i = 1, math.floor(#t/2) do
  31. local j = #t - i + 1
  32. t[i], t[j] = t[j], t[i]
  33. end
  34. return t
  35. end
  36. local function findParent(part)
  37. local tab = {}
  38. local current = part
  39. while current ~= game do
  40. table.insert(tab,tostring(current))
  41. current = current.Parent
  42. end
  43. tab = reverse_table(tab)
  44. local str = "game."
  45. for i,v in pairs(tab) do
  46. str = str..v.."."
  47. end
  48. return string.sub(str,1,#str-1)
  49. end
  50. local function addObject(pos,centerofgravityobj)
  51. coroutine.resume(coroutine.create(function()
  52. local remote = Instance.new("RemoteEvent",owner.Character)
  53. local part = Instance.new("Part",script)
  54. part.Name = "orb"..tostring(math.random(1,999999))
  55. part.CFrame = pos
  56. part.Anchored = true
  57. part.Size = Vector3.new(1,1,1)
  58. part.Shape = Enum.PartType.Ball
  59. part.Material = Enum.Material.Neon
  60. part.Color = Color3.new(math.random(),math.random(),math.random())
  61. wait()
  62. NLS([[
  63. local function AccurateWait(seconds)
  64. local RunService = game:GetService("RunService")
  65. if not seconds then
  66. seconds = 0
  67. end
  68. local last = tick()
  69. local secondsPassed = 0
  70. local connection = RunService.Heartbeat:Connect(function(dt)
  71. secondsPassed = secondsPassed + dt
  72. end)
  73. repeat
  74. RunService.Heartbeat:Wait()
  75. until secondsPassed >= seconds
  76. connection:Disconnect()
  77. end
  78. local p = ]]..findParent(part)..[[
  79. local part = p:Clone()
  80. part.Parent = p.Parent
  81. p:Destroy()
  82. local velocity = Vector2.new(0,0)
  83. local gravity = ]]..tostring(gravity)..[[
  84. while true do
  85. local op = ]]..findParent(centerofgravityobj)..[[.Position
  86. local pp = part.Position
  87. local mag = (op-pp).Magnitude
  88. local x = pp.X + (0-op.X)
  89. local z = pp.Z + (0-op.Z)
  90. local degree = math.deg(math.asin(x/mag))
  91. local xdirection = degree/90
  92. local zdirection = 1-math.abs(xdirection)
  93. if z < 0 then
  94. zdirection = zdirection * -1
  95. end
  96. velocity = Vector2.new(velocity.X+(xdirection*gravity),velocity.Y+(zdirection*gravity))
  97. part.Position = part.Position + Vector3.new(velocity.X*-1,0,velocity.Y*-1)
  98. script.Parent:FireServer(part.Position)
  99. AccurateWait()
  100. end]],remote)
  101. remote.OnServerEvent:Connect(function(plr,poss)
  102. if plr == owner then
  103. part.Position = poss
  104. end
  105. end)
  106. end))
  107. end
  108.  
  109. --
  110. addObject(owner.Character.Head.CFrame * CFrame.new(0,0,0),owner.Character.HumanoidRootPart)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement