Throwing an object with touch

Can anyone help me? I am trying to figure out how to throw and object using touch input. I would like it to behave like in the game “Paper Toss” where the object moves further away until it enters a container where it would then not be seen. it would be nice if it looked like a real toss that moves along a curved path. [import]uid: 151658 topic_id: 34516 reply_id: 334516[/import]

Hello @gorak13,
First question: do you plan to use the physics engine? If so, you can make your object into a physical body that behaves under the effect of gravity. If not, you can still simulate the curve that it might follow in a physical “throw”, but that requires some math (samples exist in the Code Share) to simulate the object’s trajectory.

Second, you’ll need to implement some kind of “swipe” detection, to determine which direction and speed the user is trying to throw the object. I located the following, in the Code Share, which you can investigate to determine if it’ll suit your needs.
http://developer.coronalabs.com/code/mark

EDIT: actually, I’m not sure if a swipe motion is exactly what you want. Do you want to throw the object more like a slingshot (Angry Birds) where the user drags the object back from a point? Or, perhaps where the user drags back a theoretical line from the object’s center which indicates force and direction? There are methods for both of these, I’m just not sure what you’re seeking. :slight_smile:

Best of luck!
Brent Sorrentino [import]uid: 200026 topic_id: 34516 reply_id: 137242[/import]

I do want it to be a swipe throw. It will not be thrown left or right, instead the user will throw dragging from bottom to middle or bottom to top, then it will be like throwing the object a distance into the background. It should work exactly as the Paper Toss game on iOS, except there will not be an effect on the object from wind. [import]uid: 151658 topic_id: 34516 reply_id: 137416[/import]

Hi again,
I think this can be accomplished, but it will require some mathematical calculations to “simulate” a 3D space (Corona is, of course, 2D). You will need to investigate a module that does this, like these perhaps:
http://developer.coronalabs.com/code/dmc-lib-trajectory
http://developer.coronalabs.com/code/trajectory-plotting

But of course, you don’t want to “toss” the object in the 2D space, so you’ll have to fake it in a front-to-back kind of view… so, basically deal with starting point and height of the trajectory, but ignore the x-coordinate movement (mostly) and instead, “scale” the object as it travels back in theoretical space.

Hope this makes (some) sense!
Brent [import]uid: 200026 topic_id: 34516 reply_id: 137474[/import]

Hello @gorak13,
First question: do you plan to use the physics engine? If so, you can make your object into a physical body that behaves under the effect of gravity. If not, you can still simulate the curve that it might follow in a physical “throw”, but that requires some math (samples exist in the Code Share) to simulate the object’s trajectory.

Second, you’ll need to implement some kind of “swipe” detection, to determine which direction and speed the user is trying to throw the object. I located the following, in the Code Share, which you can investigate to determine if it’ll suit your needs.
http://developer.coronalabs.com/code/mark

EDIT: actually, I’m not sure if a swipe motion is exactly what you want. Do you want to throw the object more like a slingshot (Angry Birds) where the user drags the object back from a point? Or, perhaps where the user drags back a theoretical line from the object’s center which indicates force and direction? There are methods for both of these, I’m just not sure what you’re seeking. :slight_smile:

Best of luck!
Brent Sorrentino [import]uid: 200026 topic_id: 34516 reply_id: 137242[/import]

I do want it to be a swipe throw. It will not be thrown left or right, instead the user will throw dragging from bottom to middle or bottom to top, then it will be like throwing the object a distance into the background. It should work exactly as the Paper Toss game on iOS, except there will not be an effect on the object from wind. [import]uid: 151658 topic_id: 34516 reply_id: 137416[/import]

Hi Brent, thanks for your responses. I checked out the links you gave me and it seems that the dmc_lib_trajectory works pretty well for what I am looking to do. Do you have a skype account or iChat or anything where I could speak with you for a few minutes. I have some more questions, it may just be easier/quicker to do it that way. [import]uid: 151658 topic_id: 34516 reply_id: 137986[/import]

Hi again,
I think this can be accomplished, but it will require some mathematical calculations to “simulate” a 3D space (Corona is, of course, 2D). You will need to investigate a module that does this, like these perhaps:
http://developer.coronalabs.com/code/dmc-lib-trajectory
http://developer.coronalabs.com/code/trajectory-plotting

But of course, you don’t want to “toss” the object in the 2D space, so you’ll have to fake it in a front-to-back kind of view… so, basically deal with starting point and height of the trajectory, but ignore the x-coordinate movement (mostly) and instead, “scale” the object as it travels back in theoretical space.

Hope this makes (some) sense!
Brent [import]uid: 200026 topic_id: 34516 reply_id: 137474[/import]

While it may not work perfectly to simulate movement through 3D space, a very simple way to get realistic 2D object movement based on a touch or swipe is to use create a “touch joint” in your object’s touch listener function. With very little code you can realistically “throw an object” around the screen with a flick of your finger. Look for the touch joint section on this Corona Labs resource page to get started: http://developer.coronalabs.com/content/game-edition-physics-joints [import]uid: 27636 topic_id: 34516 reply_id: 137995[/import]

Hi Brent, thanks for your responses. I checked out the links you gave me and it seems that the dmc_lib_trajectory works pretty well for what I am looking to do. Do you have a skype account or iChat or anything where I could speak with you for a few minutes. I have some more questions, it may just be easier/quicker to do it that way. [import]uid: 151658 topic_id: 34516 reply_id: 137986[/import]

While it may not work perfectly to simulate movement through 3D space, a very simple way to get realistic 2D object movement based on a touch or swipe is to use create a “touch joint” in your object’s touch listener function. With very little code you can realistically “throw an object” around the screen with a flick of your finger. Look for the touch joint section on this Corona Labs resource page to get started: http://developer.coronalabs.com/content/game-edition-physics-joints [import]uid: 27636 topic_id: 34516 reply_id: 137995[/import]