Applying Impulse On An Object

Hey guys, so im new to corona/lua but am in the process of making a mini-putt game. To get the power you want to hit the ball with, i have a button in the bottom right corner that you press, and then a bar that rises, and when you press the button again the time between the two presses should determine the power. I’m looking for a way to convert that time number, into an impulse on an object (the ball). I know theres the applyLinearImpulse thing, but is that just with taps? Or can I just have it apply a linear impulse without having to tap the ball with my finger

Thanks! 

Hi @smithers43,

You can calculate the time between each press using the system timer (meaning, you read the time when the first press occurs, read the time when the second press occurs, and subtract the first from the second). With this value, you can calculate whatever impulse value you need… what that actual value should be is not something that I can determine, as it will depend on your physics setup, the mass of the ball, etc. Just remember that impulse forces are very sensitive… just a tiny decimal value can send an object flying off at an insane velocity!

Here’s the timer API reference:

http://docs.coronalabs.com/api/library/system/getTimer.html

And here’s a tutorial about working with time:

http://www.coronalabs.com/blog/2013/01/15/working-with-time-and-dates-in-corona/

Hope this helps,

Brent Sorrentino

Hi @smithers43,

You can calculate the time between each press using the system timer (meaning, you read the time when the first press occurs, read the time when the second press occurs, and subtract the first from the second). With this value, you can calculate whatever impulse value you need… what that actual value should be is not something that I can determine, as it will depend on your physics setup, the mass of the ball, etc. Just remember that impulse forces are very sensitive… just a tiny decimal value can send an object flying off at an insane velocity!

Here’s the timer API reference:

http://docs.coronalabs.com/api/library/system/getTimer.html

And here’s a tutorial about working with time:

http://www.coronalabs.com/blog/2013/01/15/working-with-time-and-dates-in-corona/

Hope this helps,

Brent Sorrentino