Recoil action required on objects

Hey,

I have a collection of objects that, onCollision with something, I want them to fly up in the air slightly (recoil, i guess) but then I want gravity to kick in and they come crashing to the ground - just like if I was to give a football a slight kick.  There’s a catch though and that is that my objects are dynamic and i’ve set gravity to 0 via [lua]physics.setGravity(0,0)[/lua] (I require this behaviour for other elements of the game).  I’ve tried [lua]applyLinearImpulse[/lua] but that will just shoot the object off on a straight course into oblivion!

Any help would be appreciated

Rich

Rather than setting gravity to zero for the entire game, you can use the gravityScale property (http://docs.coronalabs.com/api/type/Body/gravityScale.html) to set the gravity to zero on some objects while leaving it enabled on others.  That sounds like it’ll solve your situation.

  • Andrew

Hey Andrew,

Can’t believe that I missed this!  This works like a dream.

Cheers buddy

Rich

Rather than setting gravity to zero for the entire game, you can use the gravityScale property (http://docs.coronalabs.com/api/type/Body/gravityScale.html) to set the gravity to zero on some objects while leaving it enabled on others.  That sounds like it’ll solve your situation.

  • Andrew

Hey Andrew,

Can’t believe that I missed this!  This works like a dream.

Cheers buddy

Rich