Mobile Touch, Swipe, Tap & Dbl Tap! Get it here... for free ;)

Hi everyone,

After searching around and picking here and there from posts and tutorials that I’ve seen, I’ve setup a simple blueprint to detect Touch on mobile/tablet devices.

It will detect:

  • Swipe (left, right, up and down)
  • Tap
  • Double Tap

Particularity of the script: (Of course, you can change this to whatever.)

  • With a swipe left or right the Player will run continuously until a tap is done to stop the player. So you just swipe once and it will run and run…
  • Jump’s while idle or running by swiping up.
  • Tap anywhere and the Player will stop and if he is stopped… well nothing!
  • Double tap and the player will fire while running or while in idle.

Basically, I do it in two steps: First, I detect the desired action and secondly, I execute the desired action.

This script as been adapted for a sidescroller game (3D or 2D). This means that the player will not rotate when changing direction, it will only flip even for a 3D character. But with some tweaking, I guess you can adapt it to what you want.

Ok so first, you have to setup two enumerators.

  • 1 For **Actions **(Run, Jump, Idle, Stop, Fire, etc.)
  • 1 For **Direction **(left, right, face, tap) (face = facing direction)

Then you setup your Character blueprint…

How it works:

  • First, through the **InputTouch **event, I determine the Touch and release action. from there, I calculate the distance between both. If the distance if far enough (You can change it to what you want!), it’s a swipe. Otherwise, it’s a tap.
  • For the Tap, I then detect if it’s a single tap or a double tap. Once that is done, I assign an action and a direction to it.
  • For the Swipe, I then detect if it’s a horizontal swipe or a vertical one. Once that is done, I determine the direction of the swipe and assign it an action and a direction to it.
  • End of that part.
  • Through the Tick event, I execute the action and adjust the direction accordingly.

Notice that before I assign a “new” action to a movement, I assign the already “done” action to a previousAction variable. I do this so that after jumping or shooting, our player can know what to do. Otherwise it would just stop after performing the fire and jump action.

The fire action is still a WIP and as another freebie (Yes I’m generous :-P) I’ve included, but not connected, some nodes that can detect what you’ve tapped on based on their tags (can be modified to mesh name, etc.). You just need to connect the Print String node for it to work. You will also notice that there’s one node for the mouse and one for the finger. When you debug, you connect the mouse one, like it is now. And when you send to your mobile, you connect the finger one. :wink:

Don’t forget to create your Enums before configuring your Character blueprint.

(right-click to save the image to see them :wink: )

Enjoy and feel free to leave your comments.

Thank you for this guide lines !

My pleasure

very helpful , thanks a lot

Thank you for these! It would be great if you could share a sample project. :slight_smile:

Very nice!Thanks!Could you make a long tap logic besides this?

Hi hls333555,

Yes you could.

  • At the start and end position (2nd screenshot), you could put in a a start time variable and and end time variable. Store the result of the difference between both in a time in a variable.
  • Then when you go to the part of is it a double tap or a tap (4th screenshot), and at the tap level (false of the branch that counts the taps), you would add a branch that would look if the tap took more or less of a certain amount that you would determine. and then if true, it would go to a "normal’ tap and if false, it would be a long tap.

Hope this helps and keep on game deving :wink:

Hi hakand,

I will try to take into consideration next time I post something here. But I really want people to do it themselves. All the screenshots are there. I believe that you learn mostly by following an example and trial and error.

Thanks for your feedback.

And happy game deving :wink:

Oh,thanks a lot.Sorry for that I did not make it clear.I mean hold events actually.When the player tap on the screen and do not release,certain events get fired.

Hi hls333555,

Unfortunately, part of the touch function is built in. You would have to mess inside the engine code in order to make modifications for that. As far as my blueprint code is concerned, you could put in a flag (boolean) that states that if the finger is still on screen to not fire the events in the tick function.

But can you give me an example of the events that are firing while your finger is still on screen?

I want to implement the functionality that hold to attack continuously,but release to stop immediately.

so when press down, you want to be able to attach and then stop attacking when your finger is off the screen… OK so that’s not a long tap, that just a press.

I’haven’t tested that, I would have to take a look at it

Any update on this?Thanks a lot!

I haven’t look at it, pretty busy with my day job, my own game project and my daughter… But I will run a quick test tonight and get back at you if UE4 traps your finger still touching the screen. Because the way my blueprint is setup, your finger has to leave the surface before anything is recorded as a touch.

from the quick little test that I have done, on the InputTouch::Pressed node, you could put a timer that if it reaches a certain amount of time and that you still have your finger on scree, do a certain action. As far as setting up the timer, that’s up to you.

But it does seem feasable since I was able to make it print a string for as long as I had my finger pressed on the screen.

thank you so much for your generous sharing.

Can you also kindly do and share how to pinch to zoom in camera ? thank you

Hi ansonkit,

thanks for the feedback. For pinch and zoom, you can take a look here →

checked that too, but I failure to re-produce that with my zero knowledge in programming. Thanks

How to add tilt controls?

Thank you very much, you saved my project and open the door for future S2