ForeverDev

Untitled

Sep 5th, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.64 KB | None | 0 0
  1. local downForce = 0
  2.  
  3. local physics = {
  4.     collision = function(body1, body2)
  5.         return(
  6.             {
  7.                 hit =   body1.AbsolutePosition.X + body1.AbsoluteSize.X > body2.AbsolutePosition.X and
  8.                         body2.AbsolutePosition.X + body2.AbsoluteSize.X > body1.AbsolutePosition.X and
  9.                         body1.AbsolutePosition.Y + body1.AbsoluteSize.Y > body2.AbsolutePosition.Y and
  10.                         body2.AbsolutePosition.Y + body2.AbsoluteSize.Y > body1.AbsolutePosition.Y,
  11.                            
  12.                 side = {
  13.                     left =      body2.AbsolutePosition.X + body2.AbsoluteSize.X - body1.AbsolutePosition.X < 5,
  14.                     right =     body1.AbsolutePosition.X + body1.AbsoluteSize.X - body2.AbsolutePosition.X < 5,
  15.                     top =       body2.AbsolutePosition.Y + body2.AbsoluteSize.Y - body1.AbsolutePosition.Y < 5,
  16.                     bottom =    body1.AbsolutePosition.Y + body1.AbsoluteSize.Y - body2.AbsolutePosition.Y < 5
  17.                 }
  18.             }
  19.         )
  20.     end,
  21.     updateGravity = function(mode, ...)
  22.         local args = unpack({...})
  23.         if mode == "increase" then
  24.             downForce = downForce + args.inc
  25.         elseif mode == "reset" then
  26.             downForce = 0
  27.         elseif mode == "jump" then
  28.             downForce = -15
  29.         end
  30.         return downForce
  31.     end,
  32. }
  33.  
  34. return physics
  35.  
  36.  
  37. --start of main
  38. game.StarterGui:SetCoreGuiEnabled("All", false)
  39.  
  40. local player = game.Players.LocalPlayer
  41. repeat wait() until player.Character player.Character:Destroy()
  42. local mouse = player:GetMouse()
  43. local screen = script.Parent
  44. local physics = require(Workspace.Physics)
  45. physics.gravity = 5
  46.  
  47. local anchor = false
  48. local anchorPos;
  49.  
  50. local player = {
  51.     body = screen:WaitForChild("Player"),
  52.     canJump = true,
  53.     speed = 5,
  54.     upForce, downForce = 0, 0,
  55.     lastSpot;
  56. }
  57.  
  58. local isDown = {}
  59.  
  60. mouse.KeyDown:connect(function(key)
  61.     isDown[key:lower()] = {
  62.         true,
  63.         key:lower() == "a" and UDim2.new(0, -player.speed, 0, 0) or
  64.         key:lower() == "d" and UDim2.new(0, player.speed, 0, 0)
  65.     }
  66.     if key:byte() == 32 and player.canJump then
  67.         anchor = false
  68.         player.downForce = physics.updateGravity("jump")
  69.     end
  70. end)
  71.  
  72. mouse.KeyUp:connect(function(key)
  73.     isDown[key:lower()][1] = false
  74. end)
  75.  
  76. local physicsBodies = {
  77.     {
  78.         body = screen:WaitForChild("Ground"),
  79.         func = function(hit, self)
  80.             hit.Position = UDim2.new(
  81.                 hit.Position.X.Scale,
  82.                 hit.Position.X.Offset,
  83.                 0,
  84.                 self.AbsolutePosition.Y - self.AbsoluteSize.Y
  85.             )
  86.         end
  87.     },
  88.     {
  89.         body = screen:WaitForChild("Float"),
  90.         func = function() end
  91.     }
  92. }
  93.  
  94. game:GetService("RunService").RenderStepped:connect(function()
  95.     for _, v in pairs(isDown) do
  96.         if v[1] and v[2] then
  97.             player.body.Position = player.body.Position + v[2]
  98.         end
  99.     end
  100.     local gotHit;
  101.     for _, object in pairs(physicsBodies) do
  102.         local collision = physics.collision(object.body, player.body)
  103.         if collision.hit then
  104.             if not collision.side.left and not collision.side.right then
  105.                 gotHit = true
  106.             end
  107.             if collision.side.top then
  108.                 anchor = true
  109.                 anchorPos = {object.body.Position.Y.Scale, object.body.Position.Y.Offset}
  110.             end
  111.             if player.lastSpot then
  112.                 player.body.Position = player.lastSpot
  113.             end
  114.             object.func(player.body, object.body)
  115.         end
  116.     end
  117.     if not gotHit then
  118.         player.canJump = false
  119.         player.lastSpot = player.body.Position
  120.         player.downForce = physics.updateGravity("increase", {inc = 0.5})
  121.     else
  122.         player.canJump = true
  123.         player.downForce = physics.updateGravity("reset")
  124.     end
  125.     if anchor then
  126.         player.body.Position = UDim2.new(
  127.             player.body.Position.X.Scale,
  128.             player.body.Position.X.Offset,
  129.             anchorPos[1],
  130.             anchorPos[2] - player.body.Size.Y.Offset
  131.         )
  132.         physics.updateGravity("reset")
  133.         player.canJump = true
  134.     end
  135.     player.body.Position = player.body.Position + UDim2.new(0, 0, 0, player.downForce)
  136.     print(player.downForce)
  137. end)
Advertisement
Add Comment
Please, Sign In to add comment