There is actually 2 different problems I want to solve, and I’m currently unable to solve either one, but the one I described in the title is the most important one.
First of all how do I trigger 2 different actions from the same button depending on the interaction (hold/press)? Think Dark Souls. In Dark Souls you sprint by holding down the B-button and you roll by pressing the B-button.
I’m currently not able to get this work. I know how I would make it work by just coding the logic myself with timers etc., but this has to be the sort of thing the new input system is meant to solve for you, right?
I came across this thread Hold and press on the same button/path without performing both actions when holding , but that deals with 2 different interactions for the same action, not 2 different actions like I have. And I wasn’t able to get that to work either way. Not to mention the image he posted doesn’t exist anymore, which I feel is embarrassing for Unity’s sake. That post is just over a year old and it’s not usable as support due to essential information missing from it.
And then there’s the second problem: In Dark Souls both actions are hardcoded as 1 bindable action with hold/press behavior. So you’re forced to bind both actions to the same key even when playing on keyboard. I want these actions to be freely bindable by the player. I was thinking I could allow my player to choose both the button/key for the action and also choose the interaction (hold/press) and that way let them freely configure it exactly how they want it and not have the limitation that Dark Souls has. But the actual rebinding is secondary, just getting this to work is more important. And like I said solving the problem in the topic title is the most important.
This is my input actions at the moment:
There you can see that I want to use Left Shift for Sprint and Space for Roll on keyboard, while I want to use the B-button for both actions on gamepad.
I’ve set the B-Button to Hold interaction for the Sprint action as shown and I’ve added a Press interaction for the Roll action. I’ve done the same for the keyboard keys.
So far in code I have this:
_inputActions.ActionMap.Sprint.performed += context => {
if (context.interaction is HoldInteraction) {
SprintInput(true);
}
};
_inputActions.ActionMap.Sprint.canceled += context => {
if (context.interaction is HoldInteraction) {
SprintInput(false);
}
};
_inputActions.ActionMap.Roll.performed += context => {
if (context.interaction is PressInteraction) {
RollInput();
}
};
But this does not work at all:
- If I tap the B-button then both RollInput() and SprintInput(false) are called. This is fine.
- If I hold the B-Button then both SprintInput(true) and RollInput() are called. RollInput() should no be called here.
- If I release the B-Button after a hold then nothing happens. After SprintInput(true) has been called I am unable to stop sprinting. SprintInput(false) is never called.
- On Keyboard I obviously don’t have the problem that both sprint and roll are called at the same time as they are on different keys, but I’m still unable to stop sprinting.
I’ve looked at the samples included with the package and none of them are helpful from what I could tell.