Corona SDK object follows “swipe” direction?

I’m trying to do something very simple as I’m new to Corona SDK, but I’m having a lot of issues with it.

 

 

What I’m trying to accomplish is when a user “swipes”, “flings”, “flicks” the screen a ball in the middle of the screen moves in that direction at a set speed. no or simple physics or anything special. So basically, if you swipe the screen at an angle, the ball will move to that angle and eventually off the screen UNLESS you “swipe” the ball again in a different direction.

I’m new to corona and still trying to figure out the touch events. Still confusing to me a little.

 

 

Any help and advice is appreciated! Thanks everyone!

hmmm to do this sort of thing, i would recommend raycasting but this is fairly complex.

I don’t have time for a long tutorial on this, but I think something like this could work:

  1. On the touch event keep track of where the touch starts and where it ends.

  2. Using those two points, figure out the angle of the swipe.

    local myAngle = math.ceil(math.atan2( (endy - starty), (endx - startx) ) * 180 / math.pi) + 90 

  3. Once you have the angle, use that to push the ball using object:applyForce()

Notes:

  • I didn’t test that code above, but it’s pulled from something that I do use.

  • Turning the angle into something you can use in Step 3 is left up to you. If I knew exactly what to do, I’d have written it down, but I don’t have the time to research that right now. It’s not something I’ve done in any of my games.

I hope that helps. :slight_smile:

 Jay

Found a thread that may help your quest:

http://forums.coronalabs.com/topic/27488-fire-bullet-from-rotating-object

 Jay

Thi

This helped! I got it working! Thanks. :slight_smile:

hmmm to do this sort of thing, i would recommend raycasting but this is fairly complex.

I don’t have time for a long tutorial on this, but I think something like this could work:

  1. On the touch event keep track of where the touch starts and where it ends.

  2. Using those two points, figure out the angle of the swipe.

    local myAngle = math.ceil(math.atan2( (endy - starty), (endx - startx) ) * 180 / math.pi) + 90 

  3. Once you have the angle, use that to push the ball using object:applyForce()

Notes:

  • I didn’t test that code above, but it’s pulled from something that I do use.

  • Turning the angle into something you can use in Step 3 is left up to you. If I knew exactly what to do, I’d have written it down, but I don’t have the time to research that right now. It’s not something I’ve done in any of my games.

I hope that helps. :slight_smile:

 Jay

Found a thread that may help your quest:

http://forums.coronalabs.com/topic/27488-fire-bullet-from-rotating-object

 Jay

Thi

This helped! I got it working! Thanks. :slight_smile: