How to get a value from 0 to 1 back and forth while a key is pressed?

Hello, I’m new to game programming and I’m trying to make a 2D game where the player can jump in a specific direction by holding the jump key.
So if the player holds the jump key, the X delta should go from 0 to 1 and 1 to 0 (0 is left, 0.5 is middle and 1 is right), back and forth while the key is being hold. So basically if I hold the key, the direction should do left=>middle=>right=>middle=>left=>…

Do you have any idea how to increment when the delta hits 0 and decrement when it hits 1 while the jump key is pressed?

Here’s a quick little BP I put together that basically uses a timeline to go back and forth and prints the location when you release. You’ll have to hook that float up to your UI and logic, but for mine I just printed it to test it out. After that, all you need to do is check that number and iterate left or right depending.

Example:
UnrealEditor_2022-10-28_22-31-23

BP:

Timeline Curve:

1 Like

Thank you very much! It works :slight_smile:

1 Like