Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Variables
- local doubleJumpManager = {Connections = {}}
- local coreModule = require(script:FindFirstAncestor("CoreModule"))
- local config = require(script.Config)
- -- Initialize
- function doubleJumpManager:Initialize(character, humanoid)
- local currentNumberOfDoubleJumps = 0
- local maxNumberOfDoubleJumps = 10
- -- JumpRequest (but actually InputBegan because JumpRequest doesn't work good)
- doubleJumpManager.Connections.JumpRequest = coreModule.Services.UserInputService.InputBegan:Connect(function(input, isGameProcessedEvent)
- if input.KeyCode ~= Enum.KeyCode.Space or isGameProcessedEvent then return end
- if humanoid:GetState() ~= Enum.HumanoidStateType.Freefall then return end
- if currentNumberOfDoubleJumps == maxNumberOfDoubleJumps then return end
- -- Jump time
- humanoid.JumpPower = config.DefaultJumpPower*config.DoubleJumpBoostMultiplier
- humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
- currentNumberOfDoubleJumps = currentNumberOfDoubleJumps + 1
- end)
- -- StateChanged
- doubleJumpManager.Connections.StateChanged = humanoid.StateChanged:Connect(function(oldHumanoidState, newHumanoidState)
- if newHumanoidState == Enum.HumanoidStateType.Landed then
- humanoid.JumpPower = config.DefaultJumpPower
- currentNumberOfDoubleJumps = 0
- -- Falling to your death by physics prevention
- elseif newHumanoidState == Enum.HumanoidStateType.Freefall then
- while humanoid:GetState() == Enum.HumanoidStateType.Freefall do
- local primaryPart = character.PrimaryPart
- -- You're in danger
- if primaryPart and primaryPart.Velocity.Magnitude >= config.HighFallingVelocityDangerPoint then
- local _, position = workspace:FindPartOnRay(Ray.new(character.PrimaryPart.Position, Vector3.new(0, -1, 0)*50), character)
- -- You're gonna die
- if (primaryPart.Position - position).Magnitude <= config.HighFallingVelocityInterventionDistance then
- character.PrimaryPart.Velocity = Vector3.new(0, 0, 0)
- require(script.HighVelocityInterventionAnimation)(character)
- end
- end
- wait()
- end
- end
- end)
- end
- -- Methods
- function doubleJumpManager:DisconnectConnections()
- for _, connection in next, doubleJumpManager.Connections do
- connection:Disconnect()
- end
- doubleJumpManager.Connections = {}
- end
- --
- return doubleJumpManager
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement