New Input System — Tap & Hold!

addam davis
3 min readDec 18, 2023

Objective: Create differing actions depending on if you press a key or hold a key.

To begin, as always, create an Input Action, and in the map editor create and Action map.

Now we can create and actions, I’m going to be creating a jump action. we will also want to add a hold interaction for 1 second.

Don’t forget to bind the action to a key.

Connect your player script to the input actions.

From here I want to know if we did a full jump, which will be ‘performed’ because we are holding down for a full second.

To begin breaking down the full jump we need to add a formula for a full jump.

Now test it in your editor, when the player holds down the jump key for 1 second, they should launch high in the air.

Now if we didn’t do a full jump, that means we are going to trigger based on the canceled event. If we don’t perform a full jump then we still want to add force to our player, just slightly less than the full jump’s worth.

Using the passed in context variable we have access to the duration of the button press. You can check that using a debug log call.

Store this information and we can insert this into our formula to give ourselves a percent of the full force.

Now you player will jump lesser then a full jump depending on how long you hold the jump key!

With this level of control you will be able to create the exact play feel you desire for your player! Don’t be afraid to experiment with your codes and I’ll see you in the next tutorial!

--

--