second LinearImpulse won't trigger

Hey guys, I’ve encountered on a little problem while working on my game, searched the forums and web for solution, but it doesn’t seem to have an answer.

The situation is that I have an object (a moving ball) in which I applied linear velocity, and this works fine, ball is moving. Then I added a collision detection when this ball is being shot, to tranform it into smaller ball. And this works too, until I try to add movement to the second ball. I mean, when collision is detected, the first ball disappear, and the second one is showing up in static. But if I want it to move (adding LinearImpulse), I get an error. I don’t know how to fix it. There’s the code: 

local ball = display.newImage("images/bigball.png") ball.x = polW ball.y = polH - 100 physics.addBody( ball, "dynamic", { density=2, friction=1, bounce=0.98 } )  local function moveball (event)  ball.x = ball.x + motionx;  end  ball:applyLinearImpulse(50, 0) function ballcollision( self, event ) if event.phase == "began" then local ball2 = display.newImage("images/bigball.png") ball2.x = ball.x ball2.y = ball.y ball2.xScale = 0.5 ball2.yScale = 0.5 physics.addBody( ball2, "dynamic", { density=2, friction=1, bounce=0.98 } ) ball2:applyLinearImpulse(50, 0, ball2.x, ball2.y) -- when I erase this line, everything is working, but he second ball pops up in static position on the screen       display.remove(ball)       display.remove(anibat)    end   timer.performWithDelay(1, removeObjects, 1) end end

ball.collision = ballcollision

    anibat:addEventListener( “collision”, ball )

Anyone have an idea why I got an error? The error states:

“[…] attempt to call a method ApplyLinearImpulse (a nil value) [C]: in function ‘ApplyLinearImpulse’ […]”

Thanks in advance for any suggestions!

bump. help please, I really need this to work:) any suggestions?

Hi @ziewmusic,

Particularly during collision events, some actions must be performed after a slight delay, just like you’re doing with the object removal. Try applying your impulse after a 1-10 ms delay and see if that does the trick.

Best regards,

Brent

bump. help please, I really need this to work:) any suggestions?

Hi @ziewmusic,

Particularly during collision events, some actions must be performed after a slight delay, just like you’re doing with the object removal. Try applying your impulse after a 1-10 ms delay and see if that does the trick.

Best regards,

Brent