How do I make a touch input controller that moves the character in the direction of the slide?

Essentially, I have a player character that moves only along the X axis. I’m trying to setup the controls in such a way that the character will move based on the direction that you swipe, but only along x. In a nutshell, I’m looking to build a control system in which you tap, hold and slide your finger around to move the character.

Any help is greatly appreciated!

Hey there, so like promised, I updated my answer to better illustrate how you could achieve this. But instead of using images I made a quick video tutorial instead (5-ish minutes)

I hope that this was helpful!

To break it down, you want to capture the initial touch, then you want to update a delta value (the amount of difference between initial touch and where the user is sliding his finger), probably every frame. So that way you know if he’s sliding his finger in front or behind his initial touch. Then you apply a positive or negative movement control on the character.

I’m not going to get into the specifics, there should be enough documentation to get you there.

If you want to be able to move not based on where your character is but based on where you press and swipe from; Do the same thing as shown in the video but instead of comparing with the character’s world location, create a new vector variable that you will set after the Input Touch Event Pressed and before the branch that checks if the player is touching the screen. Set that vector variable using the Input Touch node as explained. Then in the Compare float from that sequence instead of comparing with the character’s capsule world location, compare with the new vector variable that you created. So basically when you touch the screen it records that location and then it will check whether the player’s finger is left or right of that location until the player releases.

Thanks a lot for the video. You are a gentleman and a scholar. This is exactly what I needed and I really appreciate you taking the time to help me out. :smiley:

No problem, remember to accept the answer if it suited you for tracking purposes :slight_smile: Take care!

Great short tutorial - well done :wink:

One comment about this segment in the video. The reason you can’t find it is because you have Context Sensitivity on. If you turn that off, you will be able to find it :slight_smile: