Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local downForce = 0
- local physics = {
- collision = function(body1, body2)
- return(
- {
- hit = body1.AbsolutePosition.X + body1.AbsoluteSize.X > body2.AbsolutePosition.X and
- body2.AbsolutePosition.X + body2.AbsoluteSize.X > body1.AbsolutePosition.X and
- body1.AbsolutePosition.Y + body1.AbsoluteSize.Y > body2.AbsolutePosition.Y and
- body2.AbsolutePosition.Y + body2.AbsoluteSize.Y > body1.AbsolutePosition.Y,
- side = {
- left = body2.AbsolutePosition.X + body2.AbsoluteSize.X - body1.AbsolutePosition.X < 5,
- right = body1.AbsolutePosition.X + body1.AbsoluteSize.X - body2.AbsolutePosition.X < 5,
- top = body2.AbsolutePosition.Y + body2.AbsoluteSize.Y - body1.AbsolutePosition.Y < 5,
- bottom = body1.AbsolutePosition.Y + body1.AbsoluteSize.Y - body2.AbsolutePosition.Y < 5
- }
- }
- )
- end,
- updateGravity = function(mode, ...)
- local args = unpack({...})
- if mode == "increase" then
- downForce = downForce + args.inc
- elseif mode == "reset" then
- downForce = 0
- elseif mode == "jump" then
- downForce = -15
- end
- return downForce
- end,
- }
- return physics
- --start of main
- game.StarterGui:SetCoreGuiEnabled("All", false)
- local player = game.Players.LocalPlayer
- repeat wait() until player.Character player.Character:Destroy()
- local mouse = player:GetMouse()
- local screen = script.Parent
- local physics = require(Workspace.Physics)
- physics.gravity = 5
- local anchor = false
- local anchorPos;
- local player = {
- body = screen:WaitForChild("Player"),
- canJump = true,
- speed = 5,
- upForce, downForce = 0, 0,
- lastSpot;
- }
- local isDown = {}
- mouse.KeyDown:connect(function(key)
- isDown[key:lower()] = {
- true,
- key:lower() == "a" and UDim2.new(0, -player.speed, 0, 0) or
- key:lower() == "d" and UDim2.new(0, player.speed, 0, 0)
- }
- if key:byte() == 32 and player.canJump then
- anchor = false
- player.downForce = physics.updateGravity("jump")
- end
- end)
- mouse.KeyUp:connect(function(key)
- isDown[key:lower()][1] = false
- end)
- local physicsBodies = {
- {
- body = screen:WaitForChild("Ground"),
- func = function(hit, self)
- hit.Position = UDim2.new(
- hit.Position.X.Scale,
- hit.Position.X.Offset,
- 0,
- self.AbsolutePosition.Y - self.AbsoluteSize.Y
- )
- end
- },
- {
- body = screen:WaitForChild("Float"),
- func = function() end
- }
- }
- game:GetService("RunService").RenderStepped:connect(function()
- for _, v in pairs(isDown) do
- if v[1] and v[2] then
- player.body.Position = player.body.Position + v[2]
- end
- end
- local gotHit;
- for _, object in pairs(physicsBodies) do
- local collision = physics.collision(object.body, player.body)
- if collision.hit then
- if not collision.side.left and not collision.side.right then
- gotHit = true
- end
- if collision.side.top then
- anchor = true
- anchorPos = {object.body.Position.Y.Scale, object.body.Position.Y.Offset}
- end
- if player.lastSpot then
- player.body.Position = player.lastSpot
- end
- object.func(player.body, object.body)
- end
- end
- if not gotHit then
- player.canJump = false
- player.lastSpot = player.body.Position
- player.downForce = physics.updateGravity("increase", {inc = 0.5})
- else
- player.canJump = true
- player.downForce = physics.updateGravity("reset")
- end
- if anchor then
- player.body.Position = UDim2.new(
- player.body.Position.X.Scale,
- player.body.Position.X.Offset,
- anchorPos[1],
- anchorPos[2] - player.body.Size.Y.Offset
- )
- physics.updateGravity("reset")
- player.canJump = true
- end
- player.body.Position = player.body.Position + UDim2.new(0, 0, 0, player.downForce)
- print(player.downForce)
- end)
Advertisement
Add Comment
Please, Sign In to add comment