[Solved] How do I separately do Tap, hold, and double tap mobile controls?

Hello all,
I am working on a mobile game with the intent of being controlled with one hand. I want the controls to function like this:
Tap = move character to touched location
Hold = Teleport to touched location
Double-Tap = activate, interact, defeat enemy

So far, I have made functionality to double tap for interacts, and move to or teleport. For some reason, I cannot move or teleport, it will do both.
I have tried doing the individual actions, which leads to the same result.
I saw a forum post in another engine where they used a timer to keep track of and separate pressed or tapped key presses, so I have tried that, but the timer doesnt work right. I think it is counting by milliseconds or something.

Any ideas what I am doing wrong here?

I am unsure what you did wrong
But for teleport you could simply just go with action
Change Player position to CursorX() CursorY()

So there is no point in creating waypoint on releasing LMB but only when timer is below 2 secs

1 Like

First, dude why didnt I think of just making it an action and setting the location to the curser? Great idea, thanks.
Second, am I backwards with the time?

Let’s say i was in your shoes once

I have multiple objects it is RTS game so i need store variable in objects
If you just teleport then there is nothing to store other than just teleporting there

And idk what you mean with backwards with time?


It took me few days to figure this out (works also on mobile)

I needed all 3 methods of selection coexist
Selecting units with box
With circle
And just by clicking

To select with box you either press V or click on right most buton in lower left
And now you are in box selection mode where you hold LMB on background and move mouse to draw a box

To select with circle hold LMB for 0,4 secs in one place

And there is just selection by clicking on units

BUT on top of that since it is for single touch devices i also needed camera controls
So if you are not in box selection you can drag camera jus by clicking on background and moving mouse to drag camera

Problem was how to prevent circle selecting (hold LMB in one spot for 0,4sec) from activating when camera is being dragged

And how to prevent camera dragging when circle selection started and you move mouse

Well this was the key

I am not good with timers i literally figured it out by trail and error
So i have no idea what could be wrong with your timer

But my best idea would be 2 timers
1 for double tap other for hold

One starts after LMB is pressed and waits for idk 0,5 (adjust time to your needs) sec for another LMB press

While other starts when LMB is pressed but you delete it as soon as LMB is released

Now for 2nd one (press and hold) you just need event like 2nd timer is above 2 secs and now you do your teleport

Now on top of that i have bunch of boolean variables which go false or true
Depending on timers and what i do

So i prevent one events from being executed if im doing something else
So for example if i hold LMB for 2 secs to teleport variables which allow whatever double tap and single tap in events should disable them

Same goes with single or double tap
You need some variables to restrict yourself from doing something you do not want to happen i current scenario

On top of that you need to remember to switch variables back after you do some action
So if you set some variables when teleporting by holding LMB
You need to remember to set them back to true after you teleported (released lmb after 2 secs)

That would be my idea how to do it idk if it is best way but i would aim to try to achieve it this way

I got it working. Oddly enough, something you said made me think to just use the same check and invert it for the teleport. I also removed the waypoint from the teleport as well. Not sure why it only worked because of inverting the condition, but whatever. I also updated it so that the timer for hold resets after the entire mouse pressed check runs.

1 Like

Thanks again for the help!

1 Like