Help with 8 direction touch analog stick

Get help using Construct 2

Post » Mon Dec 30, 2013 9:20 pm

I'm having trouble with a touch analog stick for 8 direction movement. No matter what I try I can't get the player sprite to move true Left, Right, Up or Down. The player always moves at an angle like in an isometric game.

I followed Jason Jarvis' tutorial on touch analog sticks, experimented with his examples and added some events for 8direction movement. Here's what it looks like:


Image

I added the stuff below the red line. It works, but not the way it is suppose to work. Can someone help me with a solution?

I was also wondering if it was possible to use drag and drop instead, but fix it where you can drag and drop anywhere on the screen and not just solely on the player sprite to move the player sprite around. Maybe place a tiled image covering the entire screen and have that connected somehow to the player with a drag and drop behavior and have the tiled sprite box reset to the center of the screen with not in touch, but not resetting the position of the player to the center along with it? I think the accuracy of drag and drop would be ideal for touch controls, if all possible.

Boony2013-12-30 21:22:12
B
14
S
3
G
1
Posts: 87
Reputation: 1,108

Post » Mon Dec 30, 2013 11:35 pm

Provided you only want the character to move Left or Right or Up or Down, and not diagonally, this might be what you're after.

https://dl.dropboxusercontent.com/u/108799982/Capx%20Demos/MovementArrow.capx

There are other ways to do it with drag/drop, but you would need two separate controls, one for Up/Down and one for Left/Right.
Using R243 for all examples
B
69
S
20
G
6
Posts: 379
Reputation: 9,701

Post » Tue Dec 31, 2013 2:02 am

@emoaeden

Thank you. I appreciate you sharing your file with me, but I need for the player to move at angles. After the better part of the day, I wasn't able to fix the analog stick controls, but I did manage to make my drag and drop idea work. I found a way to do it in 3 events. I think with a little more tinkering, I can make it better. Here's the file for anyone who might be interested.

Touch Controls using Drag and Drop:
https://www.dropbox.com/s/yp4n0seg874zeee/DragAndDropTouchControls.capx
B
14
S
3
G
1
Posts: 87
Reputation: 1,108

Post » Tue Dec 31, 2013 3:24 am

someone else helped me with this one, ill post you the picture when i get home. it helped a ton. basically you use character.controller.x or something along those lines.
B
5
Posts: 33
Reputation: 316

Post » Tue Dec 31, 2013 3:43 am

Yes you can use Drag and Drop. But it has it's own pitfalls. however personally I think it's cleaner.

1. Make sure the D&D object always stays at the root of the object list. Putting the DD in a folder will break the system.

2. You need to work on fixing the offset of the D&D object. A D&D object doesn't center to the location of the touch. The D&D offset is where the touch occured.

3. D&D that is currently being dragged doesn't like having the .setPosition used to recenter to the touch position.

4. Ashley doesn't suggest using the D&D object for input control. Not sure why I thought the use of it was slick. But as mentioned in 1,2,3 it can break the system and there will be no BUG fix for it.


As for you to fix your current problem due to angle. That's because there is no built in dead zone. So even the slightese off center will cause the other direction to trigger. Now if you can pixel perfect control then no problem. So I don't do that.


on your
deadzone = 10

fangStick.x > fangPad.X
change to
fangStick.x > fangPad.X + deadzone
fangStick.x < fangPad.X - deadzone


alternativly you can instead check against
fangStick.XP > 10 then simulate right
fangStick.XP < -10 then simulate left
...
...



jayderyu2013-12-31 03:47:48
B
92
S
18
G
9
Posts: 2,455
Reputation: 15,113

Post » Fri Jan 03, 2014 10:44 pm

@jayderyu

Thanks for sharing the information about Drag & Drop controls. It's good to know. How long ago did Ashley make that suggestion? Maybe the issue with Drag & Drop was fixed since then? It seems to work fine for me, but I don't keep a lot of folders.

And thanks a ton for the touch control fix! I don't think I would have figured out the deadzone issue on my own.
B
14
S
3
G
1
Posts: 87
Reputation: 1,108

Post » Fri Jan 03, 2014 10:50 pm

Is the 8 direction thumbstick example i placed in This topic what you were originally aiming for?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Fri Jan 03, 2014 11:34 pm

I'm working on an helicopter game and I need more than 8 directions because the player needs to avoid fast moving missiles and obstacles, but I think your thumbstick controls work great for 8 directions movement.
B
14
S
3
G
1
Posts: 87
Reputation: 1,108

Post » Sat Jan 04, 2014 8:29 am

I think updating the touchstick-controls to create "realistic" helicoptermovement shouldn't be that hard, I guess it's a bit like the car movement with a few extra options..

I've updated the example in the hope it will now work as expected on Iphone as well.. (did you have a look at all behaviours?)


Instead of drag and drop I almost always use set to touch.x,touch.y with offset.

So on touched
- object set offsetx to touch.x-object.x
- object set offsety to touch.y-object.y
is touching
-set object x to touch.x-object.offsetx
-set object y to touch.y-object.offsety

It has the same effect as using drag and drop, really.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Jan 04, 2014 8:00 pm

I will try that, thanks!
B
14
S
3
G
1
Posts: 87
Reputation: 1,108

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests