If that’s the case, you would probably want to edit the ControlModule
directly in StarterPlayer > StarterPlayerScripts > PlayerModule > ControlModule
. Line 346 looks like the main culprit there.
You want to set it up so that it saves the last time you jumped in the main module. You can make a local lastCharge
variable right before the ControlModule:OnRenderStepped
function definition, and then make ControlModule:OnRenderStepped
call a function on the active controller declaring whether the controller is trying to charge a jump, and storing the time if so.
This is the code I used there, (Lines 307-348):
-- NEW CODE [[
local lastCharge = math.huge
local chargeAcknowledged = false
--]]
function ControlModule:OnRenderStepped(dt)
if self.activeController and self.activeController.enabled and self.humanoid then
-- Give the controller a chance to adjust its state
self.activeController:OnRenderStepped(dt)
-- Now retrieve info from the controller
local moveVector = self.activeController:GetMoveVector()
local cameraRelative = self.activeController:IsMoveVectorCameraRelative()
local clickToMoveController = self:GetClickToMoveController()
if self.activeController ~= clickToMoveController then
if moveVector.magnitude > 0 then
-- Clean up any developer started MoveTo path
clickToMoveController:CleanupPath()
else
-- Get move vector for developer started MoveTo
clickToMoveController:OnRenderStepped(dt)
moveVector = clickToMoveController:GetMoveVector()
cameraRelative = clickToMoveController:IsMoveVectorCameraRelative()
end
end
-- Are we driving a vehicle ?
local vehicleConsumedInput = false
if self.vehicleController then
moveVector, vehicleConsumedInput = self.vehicleController:Update(moveVector, cameraRelative, self.activeControlModule==Gamepad)
end
-- If not, move the player
-- Verification of vehicleConsumedInput is commented out to preserve legacy behavior,
-- in case some game relies on Humanoid.MoveDirection still being set while in a VehicleSeat
--if not vehicleConsumedInput then
if cameraRelative then
moveVector = calculateRawMoveVector(self.humanoid, moveVector)
end
self.moveFunction(Players.LocalPlayer, moveVector, false)
--end
--[[ old code
-- And make them jump if needed
self.humanoid.Jump = self.activeController:GetIsJumping() or (self.touchJumpController and self.touchJumpController:GetIsJumping())
--]]
-- NEW CODE [[
-- create charge time if not acknowledged yet
if not chargeAcknowledged and (self.activeController.isChargingJump
or self.touchJumpController and self.touchJumpController.isChargingJump)
then
chargeAcknowledged = true
lastCharge = os.clock()
end
-- Make them jump if the active controller says so
local isJumping = self.activeController:GetIsJumping() or (self.touchJumpController and self.touchJumpController:GetIsJumping())
if isJumping then
chargeAcknowledged = false
local useChargedJump = os.clock() - lastCharge > 1
self.humanoid.JumpPower = useChargedJump and 100 or 50
end
self.humanoid.Jump = isJumping
--]]
end
end
You will probably have to minimally modify all of the child modules under ControlModule
that deal with jumping, which would theoretically be Keyboard
, TouchJump
, and Gamepad
:
Module |
Function Name |
Lines |
Keyboard |
handleJumpAction |
112-116 |
TouchJump |
self.jumpButton.InputBegan:connect(...) , OnInputEnded
|
165-182 |
Gamepad |
handleJumpAction |
94-97 |
For each of these, you will want to make it so self.isJumping = true
when the input ends. For TouchJump
, I would probably set self.isJumping = false
after a delay, like a wait()
.
For Keyboard
:
--[[ old code
local handleJumpAction = function(actionName, inputState, inputObject)
self.jumpRequested = self.jumpEnabled and (inputState == Enum.UserInputState.Begin)
self:UpdateJump()
return Enum.ContextActionResult.Pass
end
--]]
-- NEW CODE [[
local handleJumpAction = function(actionName, inputState, inputObject)
self.isChargingJump = self.jumpEnabled and (inputState == Enum.UserInputState.Begin)
self.jumpRequested = self.jumpEnabled and (inputState == Enum.UserInputState.End)
self:UpdateJump()
wait()
self.jumpRequested = false
self:UpdateJump()
return Enum.ContextActionResult.Pass
end
--]]
For Gamepad
:
--[[ old code
local handleJumpAction = function(actionName, inputState, inputObject)
self.isJumping = (inputState == Enum.UserInputState.Begin)
return Enum.ContextActionResult.Sink
end
--]]
-- NEW CODE [[
local handleJumpAction = function(actionName, inputState, inputObject)
self.isChargingJump = (inputState == Enum.UserInputState.Begin)
self.isJumping = (inputState == Enum.UserInputState.End)
wait()
self.isJumping = false
return Enum.ContextActionResult.Sink
end
--]]
For TouchJump
:
--[[ old code
self.jumpButton.InputBegan:connect(function(inputObject)
--A touch that starts elsewhere on the screen will be sent to a frame's InputBegan event
--if it moves over the frame. So we check that this is actually a new touch (inputObject.UserInputState ~= Enum.UserInputState.Begin)
if touchObject or inputObject.UserInputType ~= Enum.UserInputType.Touch
or inputObject.UserInputState ~= Enum.UserInputState.Begin then
return
end
touchObject = inputObject
self.jumpButton.ImageRectOffset = Vector2.new(146, 146)
self.isJumping = true
end)
local OnInputEnded = function()
touchObject = nil
self.isJumping = false
self.jumpButton.ImageRectOffset = Vector2.new(1, 146)
end
--]]
-- NEW CODE [[
self.jumpButton.InputBegan:connect(function(inputObject)
--A touch that starts elsewhere on the screen will be sent to a frame's InputBegan event
--if it moves over the frame. So we check that this is actually a new touch (inputObject.UserInputState ~= Enum.UserInputState.Begin)
if touchObject or inputObject.UserInputType ~= Enum.UserInputType.Touch
or inputObject.UserInputState ~= Enum.UserInputState.Begin then
return
end
touchObject = inputObject
self.jumpButton.ImageRectOffset = Vector2.new(146, 146)
--self.isJumping = true
self.isChargingJump = true
end)
local OnInputEnded = function()
touchObject = nil
self.isChargingJump = false
self.isJumping = true
self.jumpButton.ImageRectOffset = Vector2.new(1, 146)
wait()
self.isJumping = false
end
--]]
Edit: I have only tested Keyboard
, I will test Gamepad
and TouchJump
right now.
Edit 2: Gamepad
works, but not TouchJump
, fixing now…
Edit 3: The ControlModule's
lastCharge
variable should be initialized to math.huge
, not -math.huge
, my bad!
Edit 4: The ControlModule
stores the TouchJump
controller in a separate variable, self.touchJumpController
, not self.activeController
.