Ask here your questions to get help using GDevelop.
User avatar
By MeX1Co
#66573 Hi... I have been trying for a week and I still cant figure it out...

What I want basically is to swipe on the left half of the screen of the mobile device and according to the direction of the swipe to apply a force on the character...

I tried to modify the multitouch example (I use the gdevelop 4 version) and i gave a condition of X < 400 to specify the left half of the screen, and it works... I can see the marker only when i touch on the left side but i cant figure out how to use the direction...

Thank you in advance for your time...
User avatar
By Lizard-13
#66575 You should keep track the touch position, saving it in variables, and then get the delta position (swipe) at some point:
Code: Select allVariable "swipeX" = TouchX() - Variable(touchStartX)

For example when a new touch is detected, save the X and Y position in two variables "touchStartX" and "touchStartY", and when the touch is released get the deltas as I did above, then you can get the swipe angle as:
Code: Select allatan2(Variable(swipeY), Variable(swipeX))

And the swipe length with:
Code: Select allsqrt(pow(Variable(swipeX), 2) + pow(Variable(swipeY), 2))


The only problem you can face is in case you can't get the touch position on release, if you can't get it you'll have to save the touch current position every frame in other two extra variables, and use these variables instead TouchX() to get the delta "swipeX" for example.
User avatar
By MeX1Co
#66616 Lizard-13 you are awesome...

So to test once more your awesomeness how would you go about making it so that when you swipe on the left side of the screen you get the swipe but while you tap on the right side you get an action???

I have the following for now...

q01.JPG (46.08 KiB) Viewed 164 times

and while the left part is working perfectly, when i tap on the right side the StarGlow variable goes to 1 for one moment and it immediately goes back to zero... any thoughts???
User avatar
By MeX1Co
#66617 scratch that... I found the problem... since it is a web game i wanted it to have both keyboard and touch controls...

so i had that when space is pressed the StarGlow variable goes to 1 and when it is not pressed it goes back to 0.... I changed it to when space is released and it works now...

You can check the motion test here... on keyboard you can use the arrows to move and space to glow, and on a touch screen swipe on the left side to determine the direction of the movement and tap to the right side to glow...