Spawn bullet when an object gets in range of the shooter

Hey all,

I’m trying to figure out the best way to shoot a bullet from a static shooter object to a dynamic object that has moved into the range of the shooter. This is my first day using Corona and its been pretty great so far, can anyone help me solve this? Right now I am trying to add the bullet during an onCollision event, but that doesn’t work because “physics.addBody() cannot be called when the world is locked and in the middle of number crunching, such as during a collision event”.

Any help is appreciated, thank you in advance!

If you want to use a collision listener, just spawn the bullet in the next frame

... in collision listener -- wait 1 ms, because -- all timers created in the current frame processing sweep, with a timer \> 0 will occur -- no sooner than the next frame -- at that point this physics processing context will be over. timer.performWithDelay( 1, function() -- add bullet creation code here end )

Do you think using a collision event on a radius object that represents the range of the shooter object to shoot the projectile would be more efficient than using enterFrame to loop over targets and shooters and calculating the distance between them to assign targets to the shooters?

I will probably just try it both ways and see what happens depending on number of shooters / targets. Any advice is appreciated though and thank you for the recommendation above!