Boolean for InputAxis?

I am trying to add a boolean variable to check in an InputAxis is True or False, True when is key is pressed and False when key is released.

I am using the boolean values returned to check if MoveForward is pressed. If it’s true, it would allow my player to sprint.

How can this be acomplished?

I’ve attached my current Blueprint for Movement Input:

Hey Justin,

MoveForward (and all “axis” events) will return a value in the range on -1 to 1.

A simple way of finding out whether MoveForward is pressed is to take the Axis value (green wire) and plug it into a float “Equal(float)” node (Math → Float → Equal(float) ). Enter ‘1’ in the second input slot and hook the bool up to a branch node.

Because the MoveForward axis goes below 0 as well as above, you should remove your “MoveBackward” input axis and use the MoveForward axis to provide both values. Here is how to set that up in the Project Settings Input section:

Setting the ‘S’ key to -1.0 will make that key the backwards key. This is true for all input axis events, so if you have a MoveRight and MoveLeft, you can remove the MoveLeft and set the ‘A’ key to -1.0 in the MoveRight config.

Hope that helps!

Hello Omnicypher,

Thank you very much for the reply, but I am not using C++ just yet. Again, thank you for the reply. :slight_smile:

Hi Justin Yap,

You can create input events for your individual keys and then create boolean variables for each being pressed. For instance, input A event>set “isAPressed” to true, on release set it to false.

Hello ,

Thank you for the reply. However, I am trying to use the boolean to check for Axis Inputs. :slight_smile:

Hi ,

Followed your advice and reverted back to using -1.0 for moving backwards. :slight_smile:

I used a float > float and float < float instead of an Equal (float) in this case as I need it to work for Gamepad input. I used the Equal (float) for Sprint instead.

Still trying to find out how I can apply the multipliers on the axis values based on what I have so far.

I’ve added some more stuff :

Now, moving sideways return a boolean value too!
I used a Equal (float) to check if Axis Value is greater than 0, if True, it means that player is moving sideways and should set isMoveSideways boolean to True, if False, it means that player is not moving sideways and should set isMoveSideways to False.