how do i throw an object?

I have an image and i want to throw it as in there’s an arrow on the bottom of the screen and when i swipe it up it moves with my finger but when i let go it keeps going…?

object:setLinearVelocity( xVelocity, yVelocity )

is that something on the right track?

Hi @SonicX278,

If the object is a physics object, then yes that’s one way. Alternatively you could use “:applyForce()” or even “:applyLinearImpulse()”.

https://docs.coronalabs.com/api/type/Body/applyForce.html

https://docs.coronalabs.com/api/type/Body/applyLinearImpulse.html

Finally, another potentially more elegant way (again, IF you’re using physics) is to use a touch joint to drag the object around, and then when the user releases the touch on the screen, break (remove) the touch joint and the object should continue on its natural trajectory. That being said, physics joints can be a little tricky if you’ve never used them before, so make sure you have a decent understanding of the Corona/Box2D physics engine before attempting this.

https://docs.coronalabs.com/guide/physics/physicsJoints/index.html

Take care,

Brent

would you write a simple code for me to get me started? cause ive tried couple things and cant seem to get it working…

well i tried the two links and i dont know if its what i need… what i wanted is when i drag an object (i have the dragObject code) and if i throw it up it keeps flying up if i throw to the right i keeps flying to the right and so on… is that possible?

Hi @SonicX278,

We (staff) can’t realistically write your code for you. However, you may get some good results by checking out the Corona “MultiPuck” sample project located in your local Corona folder:

CoronaSDK > SampleCode > Physics > MultiPuck

Take care,

Brent

oh i see… well ill look into the multipack thing.

Thanks @Brent for pointing me in the correct direction, i figured it out with the help of @roaminggamer :slight_smile:

object:setLinearVelocity( xVelocity, yVelocity )

is that something on the right track?

Hi @SonicX278,

If the object is a physics object, then yes that’s one way. Alternatively you could use “:applyForce()” or even “:applyLinearImpulse()”.

https://docs.coronalabs.com/api/type/Body/applyForce.html

https://docs.coronalabs.com/api/type/Body/applyLinearImpulse.html

Finally, another potentially more elegant way (again, IF you’re using physics) is to use a touch joint to drag the object around, and then when the user releases the touch on the screen, break (remove) the touch joint and the object should continue on its natural trajectory. That being said, physics joints can be a little tricky if you’ve never used them before, so make sure you have a decent understanding of the Corona/Box2D physics engine before attempting this.

https://docs.coronalabs.com/guide/physics/physicsJoints/index.html

Take care,

Brent

would you write a simple code for me to get me started? cause ive tried couple things and cant seem to get it working…

well i tried the two links and i dont know if its what i need… what i wanted is when i drag an object (i have the dragObject code) and if i throw it up it keeps flying up if i throw to the right i keeps flying to the right and so on… is that possible?

Hi @SonicX278,

We (staff) can’t realistically write your code for you. However, you may get some good results by checking out the Corona “MultiPuck” sample project located in your local Corona folder:

CoronaSDK > SampleCode > Physics > MultiPuck

Take care,

Brent

oh i see… well ill look into the multipack thing.

Thanks @Brent for pointing me in the correct direction, i figured it out with the help of @roaminggamer :slight_smile: