Announcement

Collapse
No announcement yet.

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

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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.

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

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

    Enjoy and feel free to leave your comments.
    Attached Files
    The Hangar Studio - Video Game Studio

    An I for an I
    (Imagination equals Innovation)

    #2
    Thank you Sir!

    Comment


      #3
      My pleasure... But don't call me sir... I still feel young! loll
      The Hangar Studio - Video Game Studio

      An I for an I
      (Imagination equals Innovation)

      Comment


        #4
        I can't enlarge attached images !!!

        Comment


          #5
          hi mhmudfadel

          right click on them, and depending on your browser, you can save them. But you can also go to my site and view them in a lightbox. Just go down in the article and click on the first image

          Here's the link http://thehangarstudio.com/2015/09/u...-mobile-touch/
          The Hangar Studio - Video Game Studio

          An I for an I
          (Imagination equals Innovation)

          Comment


            #6
            Originally posted by maparizeau View Post
            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.

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

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

            Enjoy and feel free to leave your comments.
            Hi

            Please help me for rotate the object , with Touch

            https://forums.unrealengine.com/show...with-the-touch

            Thanks.

            Comment


              #7
              hi Hamedudk

              from what I can understand from the post that you have linked in your comment, you want an object to rotate when you swipe left or right?

              Easy, in the tick event, instead of Add Movement Input, you would replace that with a rotation node. As for which one, you will have to explore that one.

              Now don't forget, this script, in the screenshots, is attached to the character blueprint. so make sure that you, either put this on the actor in question or that you specify what as to be turned.

              happy game deving
              Last edited by maparizeau; 10-16-2015, 10:12 AM.
              The Hangar Studio - Video Game Studio

              An I for an I
              (Imagination equals Innovation)

              Comment


                #8
                thanks a lot mate it help a lot , and i wish one day you can make for us a tutorial on youtube which is a lot easier .

                Comment


                  #9
                  thanks for the comment.

                  I will look into that and try to find a spot in my busy schedule.

                  Happy game deving
                  The Hangar Studio - Video Game Studio

                  An I for an I
                  (Imagination equals Innovation)

                  Comment


                    #10
                    Wow. This is a very generous resource.

                    How would you integrate holding touch screen down with your current configuration??

                    Thank you.

                    Comment


                      #11
                      Originally posted by so2gamemake View Post
                      Wow. This is a very generous resource.

                      How would you integrate holding touch screen down with your current configuration??

                      Thank you.
                      It's my pleasure. As for your question, it will depend on what you are trying to achieve. If you look at the InputTouch node, everything that has do with a press - finger touching the screen, holding down, etc, is handle on the Pressed option. And everything that has to do with removing your finger, not touching the screen, etc. has to do with the Release option. So, what are trying to do exactly?
                      The Hangar Studio - Video Game Studio

                      An I for an I
                      (Imagination equals Innovation)

                      Comment


                        #12
                        Originally posted by mhnoni View Post
                        thanks a lot mate it help a lot , and i wish one day you can make for us a tutorial on youtube which is a lot easier .
                        Hi mhnomi,

                        Sorry for the delay, I've been very busy and honestly, I kind of forgot about you request. Now I didn't do a video tutorial on YouTube. But I did put it up on my website. Which seems to be easier to follow and/or read. So hope this helps in the meantime

                        http://thehangarstudio.com/2015/09/u...-mobile-touch/

                        regards and happy game deving everyone
                        The Hangar Studio - Video Game Studio

                        An I for an I
                        (Imagination equals Innovation)

                        Comment


                          #13
                          Originally posted by maparizeau View Post
                          It's my pleasure. As for your question, it will depend on what you are trying to achieve. If you look at the InputTouch node, everything that has do with a press - finger touching the screen, holding down, etc, is handle on the Pressed option. And everything that has to do with removing your finger, not touching the screen, etc. has to do with the Release option. So, what are trying to do exactly?
                          Thank you for advice.

                          I wanted to differentiate tap(time between touch and untouch is very short) vs hold then release(time between touch and untouch is longer, like .6 seconds.)

                          I found this in other thread on the forum


                          I was wondering how to safely integrate.

                          Comment


                            #14
                            Originally posted by so2gamemake View Post
                            Thank you for advice.

                            I wanted to differentiate tap(time between touch and untouch is very short) vs hold then release(time between touch and untouch is longer, like .6 seconds.)

                            I found this in other thread on the forum


                            I was wondering how to safely integrate.
                            Assuming that his function Get Game Time in Seconds is returning an accurate number in order to determine X Start & X End, you would just add it before the Set Start Position and Set End Position. You would ignore, in your screenshot, the Normalize to Range, the X 2000 and the X Power nodes/variables.

                            But that would only allow you to do something after the press is done. If you want to do something while the press is occurring, then you would have to set it up differently. You would use the timer from the function Get Game Time in Seconds as is, and you would then add a branch, right after the X Start to see if the press has occurred for at least a certain amount of time. If True, raise flag to do action X, if False, do whatever else. You also have to keep in mind that once the player releases is finger, you will need something on the Release option in order to stop the action being done in the Pressed option if that action occured.
                            Last edited by maparizeau; 12-21-2015, 10:22 AM.
                            The Hangar Studio - Video Game Studio

                            An I for an I
                            (Imagination equals Innovation)

                            Comment


                              #15
                              Thank You Learning

                              Comment

                              Working...
                              X