Direction of Sprite Follows the Direction of Touch

Get help using Construct 2

Post » Wed Sep 18, 2013 4:15 am

Hey guys! I'm trying to figure out how to make a sprite's direction follow the direction of touch swipes. For example, if I swipe my finger diagonally, I want the direction of the sprite to shift diagonally in that specific direction. Similarly, if I swipe down I want the sprite's position to rotate into a downward position. I've experimented around with 8 Direction Movement and Custom Movement, but I haven't really come up with anything.. Does anyone have any tips?
B
9
S
2
Posts: 34
Reputation: 679

Post » Wed Sep 18, 2013 6:38 am

How about by using the bullet behavior and Touch.AngleAt
https://www.dropbox.com/s/7n9qtf2y0qhw1po/moveto-touch.capx
B
101
S
32
G
11
Posts: 1,546
Reputation: 21,727

Post » Wed Sep 18, 2013 5:04 pm

[QUOTE=ArcadEd] How about by using the bullet behavior and Touch.AngleAt
https://www.dropbox.com/s/7n9qtf2y0qhw1po/moveto-touch.capx[/QUOTE]



Thanks for the reply. This doesn't appear to be exactly what I want however. During the touch, the sprite appears jittery and seems to follow along a given axis, meaning that it only rotates around a specific point. I want it to mirror the movements of a touch swipe regardless of its position on screen. The bullet effect didn't do this, so I tried working with the Touch.AngleAt(0) command and it appeared to give the same, undesired effect. I'm still trying to figure out ways to smoothly simulate the mirrored motion of a touch swipe, but thanks for your help :) It definitely pointed me in the right direction.
B
9
S
2
Posts: 34
Reputation: 679

Post » Wed Sep 18, 2013 5:09 pm

Does MoveToward Touch.X,Touch.Y not force it to move in the direction of a swipe?
B
47
S
17
G
81
Posts: 2,226
Reputation: 48,099

Post » Wed Sep 18, 2013 5:18 pm

One way would be to save the coordinates at the beginning and the end of of the touch, and then calculate the angle of the resulting vector. Problem is this only works for one clean swipe. For long, continuous gestures with changes of direction without releasing the touch, you'd need to repeat the above action periodically. Like every 500ms or every second, get the current touch coordinates, calculate the vector using the previously saved coordinates, rotate you sprite, update those said previous coordinates with the current one, and repeat until the touch is released.

In order to get a clean rotation and not a jittery animation, you could use the Rotate Toward Angle action instead of Set Angle
B
12
S
5
G
2
Posts: 132
Reputation: 2,637

Post » Wed Sep 18, 2013 5:49 pm

[QUOTE=OlivierC] One way would be to save the coordinates at the beginning and the end of of the touch, and then calculate the angle of the resulting vector. Problem is this only works for one clean swipe. For long, continuous gestures with changes of direction without releasing the touch, you'd need to repeat the above action periodically. Like every 500ms or every second, get the current touch coordinates, calculate the vector using the previously saved coordinates, rotate you sprite, update those said previous coordinates with the current one, and repeat until the touch is released.

In order to get a clean rotation and not a jittery animation, you could use the Rotate Toward Angle action instead of Set Angle[/QUOTE]
This was one of my first approaches. I tried recording the X values and Y values then calculating that difference based on the end of the swipe, but as you said, it would be a periodic change where you would have to let go of the touch. In my specific case, this involves not releasing the touch at all, so it has to be fluent and smooth. I used Rotate Toward Angle and it still seems to be producing an undesired look. :( Thanks for the help :)
B
9
S
2
Posts: 34
Reputation: 679

Post » Wed Sep 18, 2013 5:51 pm

[QUOTE=plinkie] Does MoveToward Touch.X,Touch.Y not force it to move in the direction of a swipe?[/QUOTE]
I'm possibly doing something wrong, but when entering that expression, it's saying that MoveToward doesn't even exist, and there are syntax errors with Touch.X,Touch.Y due to the comma. I'm relatively new to using expressions, so forgive me if this is something simple that I missed.
B
9
S
2
Posts: 34
Reputation: 679

Post » Wed Sep 18, 2013 5:54 pm

What about something like this.
http://www.scirra.com/forum/how-to-make-bullet-follow-the-line-just-drew_topic53718_page1.html

Look at the example by Roj0hound. Maybe you could do something like this, but make the path invisible?
B
101
S
32
G
11
Posts: 1,546
Reputation: 21,727

Post » Wed Sep 18, 2013 6:01 pm

How about like this demo?
http://www.elf-games.com/games/move/

I used the MoveTo behavior by rexrainbow
http://www.scirra.com/forum/behavior-moveto_topic44845.html
B
101
S
32
G
11
Posts: 1,546
Reputation: 21,727

Post » Wed Sep 18, 2013 6:18 pm

[QUOTE=ArcadEd] How about like this demo?
http://www.elf-games.com/games/move/[/QUOTE]
This is absolutely ideal, the only issue is that the follow speed is a bit slow. I'm going to try to make it to where the sprite follows directly on the touch path instead of trailing behind it.
B
9
S
2
Posts: 34
Reputation: 679

Next

Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot], YoHoho and 17 guests