Advertisement
CallMeKY

Planetary Gravity

Oct 14th, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.17 KB | None | 0 0
  1. ---------------
  2. --  SECTION KEY
  3. ---------------
  4. --  TOP
  5. --
  6. --  01 02 03
  7. --
  8. --  04 05 06
  9. --
  10. --  07 08 09
  11. ------------
  12. --  MIDDLE
  13. --
  14. --  10 11 12
  15. --
  16. --  13 14 15
  17. --
  18. --  16 17 18
  19. ------------
  20. --  BOTTOM
  21. --
  22. --  19 20 21
  23. --
  24. --  22 23 24
  25. --
  26. --  25 26 27
  27. ---------------
  28.  
  29. local Force = 1500
  30. local PlanetSize = Vector3.new(100, 100, 100)
  31.  
  32. workspace.Gravity = 0
  33.  
  34. local Players = game:GetService('Players')
  35.  
  36. if workspace:FindFirstChild('Baseplate') then
  37.     workspace.Baseplate:Destroy()
  38. end
  39.  
  40. -- Generate Planet
  41. local Planet = Instance.new('Part')
  42. Planet.Name = 'Planet'
  43. Planet.Size = PlanetSize
  44. Planet.CFrame = CFrame.new(0, 0, 0)
  45. Planet.Shape = Enum.PartType.Block
  46. Planet.TopSurface = Enum.SurfaceType.Smooth
  47. Planet.BottomSurface = Enum.SurfaceType.Smooth
  48. Planet.Color = Color3.fromRGB(0, 200, 50)
  49. Planet.Anchored = true
  50. Planet.Parent = workspace
  51.  
  52. local PnPosY = Planet.Position.Y + Planet.Size.Y / 2
  53. local PnNegY = Planet.Position.Y - Planet.Size.Y / 2
  54. local PnPosX = Planet.Position.X + Planet.Size.X / 2
  55. local PnNegX = Planet.Position.X - Planet.Size.X / 2
  56. local PnPosZ = Planet.Position.Z + Planet.Size.Z / 2
  57. local PnNegZ = Planet.Position.Z - Planet.Size.Z / 2
  58.  
  59. Players.PlayerAdded:Connect(function(Player)
  60.     Player.CharacterAdded:Connect(function(Character)
  61.         local RootPart = Character:WaitForChild('HumanoidRootPart')
  62.         local Human = Character:WaitForChild('Humanoid')
  63.         RootPart.CFrame = CFrame.new(Planet.CFrame.X, PnPosY, Planet.CFrame.Z)
  64.         local BodyForce = Instance.new('BodyForce', RootPart)
  65.         local BodyGyro = Instance.new('BodyGyro', RootPart)
  66.        
  67.         local LastRegion = Instance.new('IntValue')
  68.         LastRegion:GetPropertyChangedSignal('Value'):Connect(function()
  69.             -- apply an opposing force when entering a new region to fix falling floatiness
  70.         end)
  71.        
  72.         while wait(0.1) do
  73.             if Human.Health <= 0 then
  74.                 break
  75.             end
  76.            
  77.             local PrX = RootPart.Position.X
  78.             local PrY = RootPart.Position.Y
  79.             local PrZ = RootPart.Position.Z
  80.            
  81.             print()
  82.             local Force = math.ceil(Force + (RootPart.Position - Planet.Position).magnitude ^ 1.5)
  83.             print('force: ' .. Force)
  84.            
  85.             -- can this be cleaner?
  86.             if PrX<PnPosX and PrX<PnNegX and PrY>PnPosY and PrY>PnNegY and PrZ<PnPosZ and PrZ<PnNegZ then
  87.                 print('Player is in {01}: (+X, -Y, +Z)')
  88.                 Force = math.ceil(Force / 1.5) -- too forceful when applied in multiple directions
  89.                 BodyForce.Force = Vector3.new(Force, -Force, Force)
  90.             elseif PrX<PnPosX and PrX>PnNegX and PrY>PnPosY and PrY>PnNegY and PrZ<PnPosZ and PrZ<PnNegZ then
  91.                 print('Player is in {02}: (0, -Y, +Z)')
  92.                 Force = math.ceil(Force / 1.5)
  93.                 BodyForce.Force = Vector3.new(0, -Force, Force)
  94.             elseif PrX>PnPosX and PrX>PnNegX and PrY>PnPosY and PrY>PnNegY and PrZ<PnPosZ and PrZ<PnNegZ then
  95.                 print('Player is in {03}: (-X, -Y, +Z)')
  96.                 Force = math.ceil(Force / 1.5)
  97.                 BodyForce.Force = Vector3.new(-Force, -Force, Force)
  98.             elseif PrX<PnPosX and PrX<PnNegX and PrY>PnPosY and PrY>PnNegY and PrZ<PnPosZ and PrZ>PnNegZ then
  99.                 print('Player is in {04}: (+X, -Y, 0)')
  100.                 Force = math.ceil(Force / 1.5)
  101.                 BodyForce.Force = Vector3.new(Force, -Force, 0)
  102.             elseif PrX<PnPosX and PrX>PnNegX and PrY>PnPosY and PrY>PnNegY and PrZ<PnPosZ and PrZ>PnNegZ then
  103.                 print('Player is in {05}: (0, -Y, 0)')
  104.                 BodyForce.Force = Vector3.new(0, -Force, 0)
  105.             elseif PrX>PnPosX and PrX>PnNegX and PrY>PnPosY and PrY>PnNegY and PrZ<PnPosZ and PrZ>PnNegZ then
  106.                 print('Player is in {06}: (-X, -Y, 0)')
  107.                 Force = math.ceil(Force / 1.5)
  108.                 BodyForce.Force = Vector3.new(-Force, -Force, 0)
  109.             elseif PrX<PnPosX and PrX<PnNegX and PrY>PnPosY and PrY>PnNegY and PrZ>PnPosZ and PrZ>PnNegZ then
  110.                 print('Player is in {07}: (+X, -Y, -Z)')
  111.                 Force = math.ceil(Force / 1.5)
  112.                 BodyForce.Force = Vector3.new(Force, -Force, -Force)
  113.             elseif PrX<PnPosX and PrX>PnNegX and PrY>PnPosY and PrY>PnNegY and PrZ>PnPosZ and PrZ>PnNegZ then
  114.                 print('Player is in {08}: (0, -Y, -Z)')
  115.                 Force = math.ceil(Force / 1.5)
  116.                 BodyForce.Force = Vector3.new(0, -Force, -Force)
  117.             elseif PrX>PnPosX and PrX>PnNegX and PrY>PnPosY and PrY>PnNegY and PrZ>PnPosZ and PrZ>PnNegZ then
  118.                 print('Player is in {09}: (-X, -Y, -Z)')
  119.                 Force = math.ceil(Force / 1.5)
  120.                 BodyForce.Force = Vector3.new(-Force, -Force, -Force)
  121.             elseif PrX<PnPosX and PrX<PnNegX and PrY<PnPosY and PrY>PnNegY and PrZ<PnPosZ and PrZ<PnNegZ then
  122.                 print('Player is in {10}: (+X, 0, +Z)')
  123.                 Force = math.ceil(Force / 1.5)
  124.                 BodyForce.Force = Vector3.new(Force, 0, Force)
  125.             elseif PrX<PnPosX and PrX>PnNegX and PrY<PnPosY and PrY>PnNegY and PrZ<PnPosZ and PrZ<PnNegZ then
  126.                 print('Player is in {011}: (0, 0, +Z)')
  127.                 BodyForce.Force = Vector3.new(0, 0, Force)
  128.             elseif PrX>PnPosX and PrX>PnNegX and PrY<PnPosY and PrY>PnNegY and PrZ<PnPosZ and PrZ<PnNegZ then
  129.                 print('Player is in {12}: (-X, 0, +Z)')
  130.                 Force = math.ceil(Force / 1.5)
  131.                 BodyForce.Force = Vector3.new(-Force, 0, Force)
  132.             elseif PrX<PnPosX and PrX<PnNegX and PrY<PnPosY and PrY>PnNegY and PrZ<PnPosZ and PrZ>PnNegZ then
  133.                 print('Player is in {13}: (+X, 0, 0)')
  134.                 BodyForce.Force = Vector3.new(Force, 0, 0)
  135.             elseif PrX<PnPosX and PrX>PnNegX and PrY<PnPosY and PrY>PnNegY and PrZ<PnPosZ and PrZ>PnNegZ then
  136.                 print('Player is in {14}: (0, 0, 0)')
  137.                 BodyForce.Force = Vector3.new(0, 0, 0)
  138.             elseif PrX>PnPosX and PrX>PnNegX and PrY<PnPosY and PrY>PnNegY and PrZ<PnPosZ and PrZ>PnNegZ then
  139.                 print('Player is in {15}: (-X, 0, 0)')
  140.                 BodyForce.Force = Vector3.new(-Force, 0, 0)
  141.             elseif PrX<PnPosX and PrX<PnNegX and PrY<PnPosY and PrY>PnNegY and PrZ>PnPosZ and PrZ>PnNegZ then
  142.                 print('Player is in {16}: (+X, 0, -Z)')
  143.                 Force = math.ceil(Force / 1.5)
  144.                 BodyForce.Force = Vector3.new(Force, 0, -Force)
  145.             elseif PrX<PnPosX and PrX>PnNegX and PrY<PnPosY and PrY>PnNegY and PrZ>PnPosZ and PrZ>PnNegZ then
  146.                 print('Player is in {17}: (0, 0, -Z)')
  147.                 BodyForce.Force = Vector3.new(0, 0, -Force)
  148.             elseif PrX>PnPosX and PrX>PnNegX and PrY<PnPosY and PrY>PnNegY and PrZ>PnPosZ and PrZ>PnNegZ then
  149.                 print('Player is in {18}: (-X, 0, -Z)')
  150.                 Force = math.ceil(Force / 1.5)
  151.                 BodyForce.Force = Vector3.new(-Force, 0, -Force)
  152.             elseif PrX<PnPosX and PrX<PnNegX and PrY<PnPosY and PrY<PnNegY and PrZ<PnPosZ and PrZ<PnNegZ then
  153.                 print('Player is in {19}: (+X, +Y, +Z)')
  154.                 Force = math.ceil(Force / 1.5)
  155.                 BodyForce.Force = Vector3.new(Force, Force, Force)
  156.             elseif PrX<PnPosX and PrX>PnNegX and PrY<PnPosY and PrY<PnNegY and PrZ<PnPosZ and PrZ<PnNegZ then
  157.                 print('Player is in {20}: (0, +Y, +Z)')
  158.                 Force = math.ceil(Force / 1.5)
  159.                 BodyForce.Force = Vector3.new(0, Force, Force)
  160.             elseif PrX>PnPosX and PrX>PnNegX and PrY<PnPosY and PrY<PnNegY and PrZ<PnPosZ and PrZ<PnNegZ then
  161.                 print('Player is in {21}: (-X, +Y, +Z)')
  162.                 Force = math.ceil(Force / 1.5)
  163.                 BodyForce.Force = Vector3.new(-Force, Force, Force)
  164.             elseif PrX<PnPosX and PrX<PnNegX and PrY<PnPosY and PrY<PnNegY and PrZ<PnPosZ and PrZ>PnNegZ then
  165.                 print('Player is in {22}: (+X, +Y, 0)')
  166.                 Force = math.ceil(Force / 1.5)
  167.                 BodyForce.Force = Vector3.new(Force, Force, 0)
  168.             elseif PrX<PnPosX and PrX>PnNegX and PrY<PnPosY and PrY<PnNegY and PrZ<PnPosZ and PrZ>PnNegZ then
  169.                 print('Player is in {23}: (0, +Y, 0)')
  170.                 BodyForce.Force = Vector3.new(0, Force, 0)
  171.             elseif PrX>PnPosX and PrX>PnNegX and PrY<PnPosY and PrY<PnNegY and PrZ<PnPosZ and PrZ>PnNegZ then
  172.                 print('Player is in {24}: (-X, +Y, 0)')
  173.                 Force = math.ceil(Force / 1.5)
  174.                 BodyForce.Force = Vector3.new(-Force, Force, 0)
  175.             elseif PrX<PnPosX and PrX<PnNegX and PrY<PnPosY and PrY<PnNegY and PrZ>PnPosZ and PrZ>PnNegZ then
  176.                 print('Player is in {25}: (+X, +Y, -Z)')
  177.                 Force = math.ceil(Force / 1.5)
  178.                 BodyForce.Force = Vector3.new(Force, Force, -Force)
  179.             elseif PrX<PnPosX and PrX>PnNegX and PrY<PnPosY and PrY<PnNegY and PrZ>PnPosZ and PrZ>PnNegZ then
  180.                 print('Player is in {26}: (0, +Y, -Z)')
  181.                 Force = math.ceil(Force / 1.5)
  182.                 BodyForce.Force = Vector3.new(0, Force, -Force)
  183.             elseif PrX>PnPosX and PrX>PnNegX and PrY<PnPosY and PrY<PnNegY and PrZ>PnPosZ and PrZ>PnNegZ then
  184.                 print('Player is in {27}: (-X, +Y, -Z)')
  185.                 Force = math.ceil(Force / 1.5)
  186.                 BodyForce.Force = Vector3.new(-Force, Force, -Force)
  187.             end
  188.         end
  189.     end)
  190. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement