Help with stoping key press

Im trying to stop the player from moving left or right sometimes during my game. Is their a way to block/ pause/ stop the key press for a short period of time?

you can call ‘set ignore input’ on player controller

You should not fiddle with the input system, but rather stop processing the input, e.g. if there is an obstacle in the way.

So (pseudocode):

OnKeyPressed()

    if Player.IsAbleToMove
       Player.MoveLeft()
    else 
       DoSomethingElse()

1 Like

I put this for blueprint

Hello @ddave104,
You can try doing something like this:
First of all, in your BP_Character create a Custom Event called BlockLeftRight and a boolean variable called BlockMoveLeftRight. In the event, set the variable to true to block lateral movement, then add a Delay with the duration you want, and after the Delay set the variable back to false to re-enable normal movement.

Then, in the Move function, which is in the Functions section on the left side of the Event Graph, add a Branch with the condition BlockMoveLeftRight. If the condition is true, allow only Forward/Backward movement, and if it is false, allow both Forward/Backward and Left/Right.

In my case I tested it with a Blueprint that has a Trigger Box: when the character enters the trigger, it calls the BlockLeftRight event, but you can call it from anywhere you need.


Hope it helps!

Hi, this is a great code, but not the code I’m looking for. This is just blocking I’m looking to stop the person/player input, this is just blocking the character. Thanks anyway

So you could try the following:
First create an IMC( Input Mapping Context) and remove the inputs you don’t want to use, in this case the A/D and Left/Right keys.

Then, in the Player Controller, set up a Custom Event:

This logic remove the default IMC and add your customized one, and after the desired amount of time re-enable the default IMC.

In the BP_Box, for example, it would look like this

Is this what you were looking for?

I’m also leaving a “cleaner” way to set up the logic from the previous post

What games are you making? like do you have up and down input or just left and right?

Third person game up, down, left, right. But when the character steps on top of a trap the character movement changes or just stop working. Like it’s confused

To trap character, easiest thing to do would be use Ignore Move Input on overlap, then reset it with a timer:

Should work on NPCs too if need be.

To achieve the trap effect, you can use Input Mapping Contexts (IMC) from the Enhanced Input system.

An IMC is basically a list of your Input Actions (move, jump, etc.) along with the keys that trigger them. The advantage is that you can have multiple IMCs and switch between them at runtime.

What you need to do is duplicate your IMC_Default and create an IMC_Confused. In this new context you use the same actions but inverted (for example, A = right and D = left). If what you want is that the character cannot use those keys at all, simply remove those entries from the IMC.

IMC_Default


IMC_Confused

IMC_Block/ignore

In the Player Controller you already have the event set up (the one I showed in the previous post) and its logic is as follows:

  • Remove the IMC_Default (the basic controls).

  • Add the IMC_Confused (the modified controls).

  • Wait for the number of seconds you define.

  • Re-enable the IMC_Default.

To call this event from the trap, use a Trigger Box. In the Event Graph, with the OnActorBeginOverlap event (which fires every time the player collides with that Box Collision), cast to your BP_ThirdPersonPlayerController and from there call the event in the Player Controller that switches between IMC_Default and IMC_Confused.

This way, when the character steps on the trap(box collision), their controls are inverted or disabled temporarily, and then return to normal.

Here’s some documentation on Enhanced Input and Input Mapping Contexts

If this isn’t exactly what you’re looking for, could you share a bit more about what you’d like the trap to do or how it should work?