How to assign different functions to the same key (single and long press) and how to limit tracing?

I’ve created a springboard mechanic inside my movement component, which looks like that:


(the bottom one is the Springboard Movement function called from Springboard Update → Springboard Movement)

My problem is, that I would like to set up my character blueprint to use the same key (Jumping input) for both jumping and springboarding, but jumping should happen when the button is pressed one time, and springboarding when it’s held for some time. The whole idea looks like this: Pressing jump input starts the springboard movement’s line tracing, and when the trace is not blocked by a wall, character jumps. But when the trace is blocked by a wall (so basically detects a specific wall) AND the jump key is still held, the character instead of jumping does the springboard movement.

The second thing is, how to limit function execution for a specific amount of time? The tracing should occur only for a short amount of time after pressing the jumping key and then stop to avoid any interferences from another movements.

I’ve tried many things, but all of them were unsuccessful, so I would really appreciate your help :slight_smile:

Hello Again :smiley:!
Take a look at this video : Link

You can then do a simple branch check On Key Event (Released Pin) to see if the time held was greater than a certain amount or it was just a tab then run different function on True or false.

For the second thing you can do that in tick or using timers like you showed.
Lets say in Tick I can create a branch that checks if it’s Ok to call Trace function the condition can be a float variable that holds time since the trace has been running, all you need to do to run the trace is set the time variable to 0 and it will keep on tracing until time is greater than a certain value.

For time you can use Get Delta time and Add that into your Time variable, and when ever you wanna start tracing just set that time variable to 0.

Try this:

On pressed:

  • get game time since creation and assign to a float pressTime.
  • start a timer with float delayTime as Time (not looping)

On release:

  • if get game time - pressTime < delayTime → execute single press and delete timer.
  • if player never lets go the timer will just run. Nothing will happen when player releases after this point because the condition above will be false.

So if player presses and releases faster than the time set to the timer, run single press event and cancel timer. If player holds then just the timer finishes and runs the event.

No tick needed. :grimacing:

Hope it makes sense.

There’s also Enhanced Input