Joystick- like Movement

hmm yeah, but even if i change the layer of button to base layer, it still gives me the same result, always moving the character to the left side even if the touch is > than centre of button.

You don’t want the button to be on the base layer, because then if the character move to the right, you leave the button behind as you move the camera on the layer to follow the player.
You want to check touch on the GUI layer and keep the button on the GUI layer.

It works for me. It is maybe your device then.
All I do and did again just to be sure,

  1. unzip the archive you have uploaded.
  2. open the project in GD5
  3. in BOTH conditions to check position of touch, change layer to “GUI”
  4. save and export

Done. It works on my side on my touch devices :confused:

If you mean it doesn’t work with the mouse on PC that is because you are checking position of the touch and not the mouse.

If you are testing this on a Windows tablet maybe the multi touch events does not work on Windows? Could anyone confirm this with a Windows touch device please?

If you are testing this in the browser on an android or ios device, you may need to hard refresh the browser to make sure the game update in the cache.

In case you are exporting to APK and install on your device then I have no idea why it doesn’t work for you, hope someone can figure this out.
I would be curious what is going on, on your end :neutral_face:
Anyone?

hmm, ok let me try one more time on exporting the whole apk to an android phone and see if this problem still exist. It is very weird that it only works on your side and i have about 3 smart phone (both android and iphone), all of them gives me the same result, means that whenever i touch the button, whatever location it always return value < than the centre of the button, thus always walking to the left side.

Yeah it is weird. Would be nice if a 3rd party could confirm if it doesn’t work. Since it works for me I can’t figure out what the problem is. :frowning:

Hello,

I’m glad to join the forum :slight_smile:
The solution works. If not used a multitouch. If you first touch the screen elsewhere after that, the second touch is not treated separately. The JoysticktouchID alwways 0. Now I’m making an 360° analog joystick control and I couldn’t fix this error. That’s why I use draggable object behavior. And it works like a dream. I’ll try to upload the working version to the forum in 1-2 days. :smiley:
Sorry for my bad English. :wink:
Gabor

In case you want to implement true multi touch you want to look for not only a touch but a “new touch”.
In my example when you touch the joystick I pick the touch ID so I know which touch is the one controlling the joystick, the second touch did not really concern me as long it is the jump button but indeed it can mess up I might improve it when I have some time.

EDIT:// fixed it.

hmm, ddabrahim, currently now i am trying to improve further for the joystick, the idea is to put a big sprite(Movement) on the left side of screen. As long as the touch is on Movement, the joystick will follows your touch instead of fixing the location of joystick. What i tried to do is creating the joystickbgm and the joystickpoint at the x,y position of touch. Then from there if the touch x position is < than the joystickbgm(centre) position, the player will move left, if touch x position is > than the joystickbgm(centre) position, the player will move right.

It works weirdly as most of the time, when player is jumping and i try to move him to left or right, player will always move to left hand side in midair. I was wondering did i define the centre of touch wrong, or is there other thing i can do to keep it as accurate as possible. For example i want it to be like when touch is on the screen, if i move to left, player go left, if i move to right, player go right.

I think it is the same problem GyGabor was mentioning. If you touch the jump button or any part of the screen before the joystick it cause problem with the joystick because the condition “Cursor/touch is on Object” does not take in to account multi touch, only 1 touch at the time. In order to solve this, you need to check for “new touch” in case the joystick is the second touch (so it is new) but also keep the current condition in case the joy is the first touch.
You are going to need to use the OR and AND blocks to work around this.
I have updated my example on itch.io with the solution, take a look and see if it solves the problem for you.

GyGabor also shared a nice example for dual joystick, have a look:
Simple dual stick 360 shooter - #7 by GyGabor

hmm, Thanks! I managed to work it out after consider changing it to draggable object for the joystick instead of touch. Work much smoother and more responsive for the movements. Thank you again!

Are you saying that making the joy a draggable object did solved the problem?
I fail to see how when you are comparing the position of the touch to the center point of the base. How the joy is moving got nothing to do with it :confused: Or am I missing something? Probably :smiling_imp:

Check out the code down here. Basically for me, draggable control feel much smoother and error-less compared to the touch control. Mainly when it comes to 2nd touch on the screen (eg: After pressing jump button, direction button is moved.)

For touch control, I am using the exact same way of comparing the x position to the centre point, but somehow it always goes wrong sometime for the 2nd touch on screen. ( eg: sometime after pressing jump button, while intended to move right hand side, it always move the character left).

Oh. I didn’t know that the draggable behavior support multi touch out of the box. Interesting :laughing:

Hmmm. No. It doesn’t seem to support multi touch. Not sure why is it working for you then.
Anyway, if you experience the problem again with the character moving left for no reason, take a look at my joy example on itch.io, it should work now. I hope :stuck_out_tongue:

Multitouch works with Draggable behavior in the other joystick topic you’ve linked, the one with the example. I’ve even shared a modified version there that checks if the sticks are being dragged for code easiness :slight_smile:

Ah, I know what I did wrong :mrgreen: What I tried was is simply add some draggable objects and drag multiple at the same time and when I dragged two at the same time, the one overwritten the other, they did not move independently from each other. But that is because it was the instances of the same object but I’m not sure why I did that. Why would you want to use the same object to do different things :astonished:
It works with different objects.

I should take some break I guess and get some sleep.

So it doesn’t work with instances of the same object?.. what a shame :frowning:

Hey guys, I faced another bug with the draggable control again check out the code below:

The problem is that, when i enter the next scene while dragging the control button, even after i reset the location of the drag object(movement control) when i enter new scene, the button is unable to work, as if the system thought i am still dragging the object (instead the button is already reset to the location). I tried at the beginning of scene, off the behavior of draggable object and after 0.1 sec, enable the draggable behavior again. It doesnt seems to do anything with the bug. I tried with the condition to check touch has not ended, object is being dragged, reset the location of button. Still doesnt work. When the button reset to the location, it is indeed at the location i need, its just that dragging doesnt work anymore.

Anyone has any idea how to fix this bug?

How about disable draggable behavior at the beginning of the scene and enable it if the user do not touch the screen. Alternatively, after each scene go to a score screen with no joystick where you display the current score or any stats and contune to the next scene after the player pressed OK or something.

well i tried to disable the behavior at the beginning of scene then enable it right after, it doesnt work. is there any other way besides adding a new scene after each level?

End up fixing it by disabling the draggable behavior everytime before i change to next scene. Then enable it at the beginning of scene. That did fix it :slight_smile: