The problem is that for an ideal situation, you’ll want the Player to change directions if you add a new input. This means you need to track when the button’s are pressed.
The solution I’ve made below is probably ideal for you, because if you press Up
then Right
, then let go of Right
while still holding Up
, then you’ll resume going up until you let go of Up
.
First, we need to change the inputs from being Axis values to being Events that you can use them to track when they happened.
Go to Edit → Project Settings and find the **Engine - Input ** section on the sidebar. Then setup your inputs like this.
Now create five DateTime
variables. OffTime
, ForwardTime
, BackTime
, RightTime
, LeftTime
.
Then setup your actions to record when they are pressed and released.
Now create a new function to get your desired direction. This is the brain of choosing which way to go based on what DateTime
values are stored in your variables.
It chooses which value was pressed most recently, and passes on the desired direction vector and the winning time value.
Now last step, is simply inserting that function into your Tick
Event where you were deciding where to move the Player
And you’re done!