@gaby424 said:
@TT
What do you mean by "#This will not work for multiple touches. See next code example!"
1. not more than 2 fingers in the same time?
2. or if i make a drag and some tapstaps, than release the drag and start the drag again with another taps will not work?
I was just meaning that the first example will only track a single touch/finger. You could use more than one tap/finger at the same time, but the code will only respond to the first touch/finger.
what did you mean on line 64?
first_touch_down = true;
first_touch_down is not defined yet.
I commented that line.
Whoops, that was a leftover variable. Initially I was using first_touch_down
to detect whether a touch is down instead of checking first_touch_index != -1
. That line should be removed, since it doesn't do anything.
It is working ok if I start to drag with the first finger. Than start to tap multiple times with second finger. But if I release the drag finger and try again to start to drag, the gun doesn't follow the event position. I think it is because the condition from line 72
if (event.index == first_touch_index):
if I remove condition it works with the following part but than the tap doesn't work anymore.
I think this is because I have tore reset var first_touch_index and var second_touch_index to -1 when my hands are not on the screen(like i make a pause).
I will test more tomorow.
I'm not sure why it is not working when you release. Resetting the variables manually should help though. I also realized that I made a few mistakes in the example code I posted, which might be contributing/causing the problem.
Here is a printscreen with the TT implmented but still under review to make it work.

Looking at the code again that I posted, and looking at the image, I realized I made a few mistakes. Theoretically, a few changes should help and maybe fix the drag issue.
First, lines 76 to 87 need to be deleted. They are messing up the first touch. I accidentally forgot to remove them when I copy-pasted the code from the first example to use as a base.
Lines 94 and 95 should be removed if you want only the first finger to be able to move the gun. If you want any/all fingers to move the gun, then lines 94 and 95 should work fine.
(NOTE: I have not tested the code, I am just going off what I know about Godot and GDScript. I don't have a device I can test with handy, so unfortunately I cannot test the code to know whether it works)

Also I adapted this basic code and it also seems to work. But with the same problem, that I have to make small drags made by mistake to act like a tap.
I'm not sure how to fix the small drag acting a like a tap problem, unfortunately. It might be because, as far as I can tell, looking at the code it seems that every touch/tap will fire a bullet, and every drag will move the gun. I don't know if this is what you are intending or not.
One thing you could try is checking the speed
property of the InputEventScreenDrag
, and if it is lower than a certain value, then ignore the event. Something like this:
if (event.speed.length() < 16):
return;
else:
# Do whatever is needed with the drag here
Happy to help! Hopefully this helps. :smile: