Can I use the new Input Action System to detect a jump

I have searched for this everywhere, and the lack of an answer probably means my answer is NO, but I thought I would ask anyway.

I am not wanting to assign a specific key such as ‘space bar’ in the Input Action System, and then code in a jump response. I am wondering if it has any sort of way I can get an event fired when the player tries to jump with whatever key bindings or controllers they are using for jump.

I was using this…

	local PlayerModule = require(game.StarterPlayer.PlayerModule)
	local Controls = PlayerModule:GetControls()
	local lastJump = false

	game:GetService("RunService").Stepped:Connect(function()
		local moveVector = Controls:GetMoveVector()
		local moveVectorVar = player:GetAttribute("Flags_MoveVector")
		if moveVector and moveVectorVar then
			if moveVector.X ~= moveVectorVar.X or moveVector.Y ~= moveVectorVar.Y or  moveVector.Z ~= moveVectorVar.Z then
				player:SetAttribute("Flags_MoveVector",moveVector)
			end
		end

		local controller = Controls:GetActiveController()
		if controller then
			if controller:GetIsJumping() or (Controls.touchJumpController and Controls.touchJumpController:GetIsJumping()) then 
				--Jump state is ON
				if lastJump == false then
					player:SetAttribute("Flags_JumpState",true) --JumpState.Value = true
					lastJump = true
				end
				local jump = player:GetAttribute("Flags_Jump")
				if jump then
					player:SetAttribute("Flags_Jump",jump+1)
				else
					player:SetAttribute("Flags_Jump",0)
				end
			else
				--Jump state is OFF
				if lastJump == true then
					player:SetAttribute("Flags_JumpState",false) --JumpState.Value = false
					lastJump = false
				end
			end
		end
	end)

I tried to follow this guide, but to be honest it didn’t really make any sense to me.

So, just on my own I got the vector movement setup, but I still can’t figure out how to detect a jump.

NOTE : I don’t want to use a humanoid, because sometimes I use this module for non humanoid players.

I appreciate any help with this, thanks in advance.

You can just re-use their IAS Instance that they use for jumping. Does that work?

But since you posted your previous code, I can look at it and add the thing in the guide.

Although the old one is also specifically checking the touchJumpController even though you used :GetActiveController(), that is confusing, nobody should have to do that.

For the Input Action Instances, you can have multiple keybinds under an action and then listen for events on the Action itself.

 

But for what the guide is pointing out, also since you have :GetMoveVector

In this case JumpAction. But of course this just says that the Jump Action is being triggered, not that the “entity” is jumping. And I am not even sure if the old system cared either.

And this is cross-platform. The touch button jump button is supposed to trigger JumpAction, so you can just connect all events to it, no need for separate checks.

In case the Mobile Jump Button doesn’t trigger JumpAction, then make a bug report because that must be a fault by Roblox then.

I will look through your tutorial again, and see if it can make more sense to me. Yes, I see that in the original code, what you mean about unnecessary having both GetActive and touchJump controllers.

The way I needed the jump detection, was that it would trigger a jump action even if the character is not jumping. I just needed to know whet roblox detected a jump attempt.

I will update this if I get it working.

Oh then your best way is to just check JumpAction that Roblox creates!

Do you think you could point me to a quick little pseudo code that would show me how to do that?
If you don’t mind.

I think

local jumpAction = inputContextFolder:WaitForChild("CharacterContext"):WaitForChild("JumpAction")

jumpAction.StateChanged:Connect(function(value)
   print("Jump Action Active:", value)
   print("Jump Action Active:", jumpAction:GetState())
end)

 

And this here

https://setup-rbxcdn.github.io/ref/class/InputAction.html

https://create.roblox.com/docs/reference/engine/classes/InputAction#GetState

2 Likes

Ok, I figured it out, thanks so much.
This is what I ended up with…

local player = game.Players.LocalPlayer

local PlayerModule = game.StarterPlayer:WaitForChild("PlayerModule")
local InputContexts = PlayerModule:WaitForChild("InputContexts")
local CharacterContext = InputContexts:WaitForChild("CharacterContext")
local JumpAction = CharacterContext:WaitForChild("JumpAction")
local MoveAction = CharacterContext:WaitForChild("MoveAction")
	
MoveAction.StateChanged:Connect(function(state)
	player:SetAttribute("Flags_MoveVector",state or Vector2.zero)
end)
	
JumpAction.StateChanged:Connect(function(state)
	player:SetAttribute("Flags_JumpState",state)
end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.