apply force to an object

I have a problem in my game . is there a way to make a physics body make able to apply force and throw it in any direction?Please help me out ..

Try this:

1
2
3
vx, vy = item:getLinearVelocity()
 
item:applyLinearImpulse(vx, vy)

There is a helpful example of this already on your computer;

CoronaSDK > SampleCode > Physics > MultiPuck

Peach :)

thanks for the help..But I could not understand how to use as nthing is happening.. please help me..

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
physics = require( "physics" )
physics.start()
physics.setGravity( 0, 9.8 )
 
ball = display.newCircle(400,100,100,100)
physics.addBody(ball)
 
function ballf(event)
    if event.phase == "ended" then
       vx, vy = ball:getLinearVelocity()
       ball:applyLinearImpulse(vx, vy)
    end
end
 
ball:addEventListener("touch", ballf)

Play with the multipuck code, read through it, bit by bit - your code is missing some important stuff multipuck is using.

views:1808 update:2011/12/29 9:44:01
corona forums © 2003-2011