Direction of Sprite Follows the Direction of Touch

0 favourites
  • 11 posts
From the Asset Store
16 Direction Capx
$3 USD
40% off
Rotate & Animation for 16 Direction & Mouse Direction
  • 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?

  • How about by using the bullet behavior and Touch.AngleAt

    https://www.dropbox.com/s/7n9qtf2y0qhw1po/moveto-touch.capx

  • How about by using the bullet behavior and Touch.AngleAt

    https://www.dropbox.com/s/7n9qtf2y0qhw1po/moveto-touch.capx

    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.

  • Does MoveToward Touch.X,Touch.Y not force it to move in the direction of a swipe?

  • 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

  • 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

    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 :)

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Does MoveToward Touch.X,Touch.Y not force it to move in the direction of a swipe?

    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. <img src="smileys/smiley4.gif" border="0" align="middle" />

  • 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?

  • 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

  • How about like this demo?

    http://www.elf-games.com/games/move/

    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.

  • With MoveTo you can adjust the speed.

    Here is a screen shot of the event sheet and the properties for moveTo.

    <img src="http://content.screencast.com/users/ArcadEd/folders/Jing/media/4e1cd540-250a-4231-987b-05e301141228/2013-09-18_1022.png" border="0" />

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)