New Input System , Different Actions ,but same button? is possible?

Scenario: I have the “ActionMap” “PlayerGroundAM” that contains two actions: “Prone” and “AimAndMove” , among other Actions in the ActonMaps .
I want to use the same key to switch between both actions.
I need to control which action is active at a given time (for example, Prone when you are Prone and AimAndMove when you are not).
ActionMap (AimAndMove) behavior when using keys (ArrowUp or Arrow Down):

Since the behavior of the “arrow down” key when used in “AimAndMove” is to allow aiming while moving in vertical directions, only while moving, as in the counter, if you hold down a direction, let’s say “arrow right” it will move to the right, but if I hold the same key and then press “Arrow down”. What do you think will happen? Well, it will point in one direction while moving, you understand.
ActionMap (Prone) behavior.
This simply makes the Player execute the Prone animation, meaning that it can do Prone!. It only needs the Player to be still, without any physics, idle, idle!, if it is still and presses down. What do you think should happen? Well, it should do Prone.
To get out of prone, just press any arrow key, it can move naturally horizontally (MoveOnGround) or repeat the cycle of moving pointing (AinAndMove).

As you can see in the picture, I have few ActionMaps, related to PC-Scheme, only PC, I can Move horizontal (MoveOnGround :smiley: ) , and move horizontal while aiming (AimAndMove :smiley: ) in 8 direction! that is Crucial! (Like A contra NES).
I am very happy to the movement and Aiming. I can move left-fight and if I press (Up-Down) I can Aiming in 6 directions , this is exactly that I want!. The problem I am stucked now is the “prone” actions…
I need to “Prone” only and only if the player is idle (not movinng) why? because if he press “down” he is aiming certain directionr. So (Up-Down ) keyaboard are mutuable in terms of easy comprehenssion.
when the player is “idle” with no force even… if I press “prone” (arrow down) I must Prone! and that! not happen!..

I also attached the relevant code , special the “input class” that I am using for this approach.

PlayerInputActionsController.cs (10.5 KB)

also I attached the PlayerMomventGround as pseudo-business logic
PlayerMovementGround.cs (3.5 KB)

The behaviour of the “AinAndMove” Action ! here it is :

I only interesting in 2D games. I pretend to to use New input system for basic small games. As you can see Aiming and move is critical for this game :smiley: … I need to prone now, using the same button, differnet actionmap… I think Inputsystem must be official and accesible in terms of classics games…I need Unity need that extra force. I want to hear suggestions/solutoins from people who really experience on game dev and input system, do not waste my time and your time.

Yes you can have different actions for the same input. There’s a few ways to go about this.

First would be to make your inputs more generic. You could just have a generic ‘Down’ input, and whether the play aims down or goes prone is simply handled by your code.

Or you subscribe/unsubscribe to various InputActions depending on what the player is doing. If the player starts moving, unsubscribe to the Prone InputAction and subscribe to the movement ones, and vice-versa when they stop moving.

mmm I do not know if that is the way I want… I am stacked… but not problem… I am hearing all other options.

How do you know? Have you tested it?

Do you mean unsubscribe/subscribe in OnEnable or OnDisable from a MonoBehaviour lifecycle? Or should I use ‘Enable’ and ‘Disable’ from the InputActions? I usually subscribe/unsubscribe in OnEnable, OnDisable, and OnDestroy. I want to know if I need the exact setup from the first picture I uploaded at the beginning of the post to create the ‘Contra’ style Aim and Movement, and Prone mechanics.

That’s… not what I said at all.

When your player stops moving. Unsubscribe from the aim input, and subscribe to the prone input; and vice versa when they start moving. This has nothing to do with MonoBehaviour life cycle callbacks. You’re going to have to code the conditions for this yourself.

![enable-disable-actionamap|690x396](upload://nILX9sdpdiTTEhWzSPOxK20pI1A.png

Do you meant something like this? This method allows to keepMoving while Aiming…

as the “region says:” #region KEEP MOVING AND AIMING (HOLDING DIRECTION RIGHT-LEFT + HIT UP ARROW OR + HIT DOWN ARROW (INPUT SYSTEM CALLBACKS)

… So I must to Enable and Disable the Actons?

I also attach the Acitons to refresh

Uploading: aremoves.PNG…

Something like this?

I can not find the solution , Unity input system is not easy to handle limited button such as contra clone.

PlayerMovementGround.txt (2.1 KB)

PlayerInputController.cs (6.0 KB)

It’s entirely possible and my described method would work fine, I have done it on the regular.

If anything you probably need a simple state machine to clearly delineate between when the player is and isn’t moving, so you can modify what controls are active and inactive.

It should be straight forward. Which particular part are you having difficulty with?

edit: spiney suggested the state machine before i’ve finished writing my lengthy comment. that is exactly what you need

instead of messing with inputs, disabling not disabling a mess, you need to structure your code using the state pattern so you can control what the player can do and how the stuff on screen reacts in different situations by separating the code in these states.

all these bellow are separate scripts

so if you are in IDLE STATE and player presses left you switch to WALKING STATE and there you move the player, play walk animation, if player releases the left button you switch back to IDLE state. Now lets say you get hit by an enemy while walking. you switch to GOTHIT STATE where the character in game stops the movement, plays the hit animation and you also have introduced a timer that sets a boolean which doesn’t let the input code to run. if the boolean is true then you don’t care about the input. once the timer runs out, boolean is set to false, you exit the GOTHIT STATE move to IDLE

this is for example a simple structure for a simple 2D sidescrolling fighting game

so i have this jump which has the same issue you have described, the same jump button needs to do something else if is combined with different inputs.

I know it doesn’t make sense out of context but if the player is moving then jump forward if not jump in place

if (actor.movementInput != Vector2.zero)
{
    actor.currentState = new State_JUMP_FORWARD(actor);
 }
else
{
    actor.currentState = new State_JUMP_INPLACE(actor);
}

anyway, youtube has a lot of tutorials about the state machine pattern in unity, but watch a couple of them as each author may implement the pattern a bit different.

but your jump button ? is the button you have duplicated? right? but if the button is trigger is not problem!..the problem is when it is a vector 2D… in my scenario (contra) I am using “up arrow” to AimAndMove (Actionmap) and AimingUp (ActionMap)…both are different , but use “up arrow”…

The State pattern focuses on implementing a Finite State Machine, right? Isn’t it over-engineering for a Contra clone? I only have an issue with the ‘up arrow’—I can’t manage two ActionMaps using the same key, especially if both have ActionType set to Vector2D.

It’s hardly over engineering. It’s a common as muck pattern for game dev. If the original Contra wasn’t using a state-pattern, they probably wish such patterns and information surrounding them were readily available like we have these days.

And just because you’re making an old game doesn’t mean its simple, or the code involved was simple. Lots of these old games are low key master pieces of early computer engineering.

State pattern does not imply a finite state machine either. It be anything, an enum, a boolean, etc.

You just need any form of state to enable/disable the right actions depending on state. That’s the underlying principle of this. That’s the underlying principle of thousands of character controllers.

You could also just have a distinct separation between the inputs themselves, what reads the inputs, and what acts on said inputs. Inputs shouldn’t drive the game on their own, your code should. Simply read the right inputs depending on state/context.

I got this “ActionMaps”…
I have not idea if I need to control “diagonals” there? I meant does not exit “diagonal” keys, it is the combination of “up+rigt” (diagonal superior right ) , “Up+left” (diagonal superiro left) , "Down+right " (diagoanl inferior right)…etc… that it is the thing I need… and also use the “Up arrow” when idle to AimUp.

Again, don’t use the raw inputs to drive your logic. Its just data/values. YOUR code should drive the game, reading the input values it cares about at the logical time to do so. So you will need to code the logic to interpret the right inputs to get the right movement behaviour.