Question for the physics gurus

So I’m animating a number of balls around the screen on an enterframe listener, making sure they dont overlap the screen edges and reversing their direction if so.

I’ve attached a collision listener to each ball and want a linearImpulse should two balls collide.

This is all working perfectly - however I’ve noticed that having added the impulse upon collision that balls are now falling outside of the screen edges.

If I take away the impulse then it all works fine again. I suspect it’s something to do with the issue of changing an objects properties while an event is occurring; however my issue is that because the animation is on an enterframe listener then these objects are constantly changing their properties.

Any help to avoid this would be grateful - picture it as a physics enabled version of asteroids I guess. [import]uid: 33275 topic_id: 35317 reply_id: 335317[/import]

Have you tried http://docs.coronalabs.com/api/type/Body/isBullet.html [import]uid: 202223 topic_id: 35317 reply_id: 140371[/import]

Have you tried http://docs.coronalabs.com/api/type/Body/isBullet.html [import]uid: 202223 topic_id: 35317 reply_id: 140371[/import]

You said “So I’m animating a number of balls around the screen on an enterframe listener, making sure they dont overlap the screen edges and reversing their direction if so.”

I don’t know exactly what you are doing with them, but could you not put some chunky walls outside the edge of the screen, and attach static physics bodies to them? Then use linear / angular impulses on your ball objects to move them around and let the physics engine handle the reversing directions etc?

If the walls are thick enough then your objects shouldn’t go through them unless they are going super fast, and it saves you having to manually calculate the directions. [import]uid: 84115 topic_id: 35317 reply_id: 141238[/import]

I’ve noticed that if you have a lot of ‘balls’ and use an enterframe listener, then occasionally they will pass thru even static barriers, especially if you have everything set to 60 fps.

To remove those occasionals, I reduced physics.setPositionIterations and physics.setVelocityIterations.
And use an timer.performWithDelay( 5 or even 10) instead of enterframe to handle movement and reverse direction on screen edges
And this is using linearImpulse triggered by explosions and looping thru the balls table to check for distance from explosion - with allowable distance set to half the screen width.

And things run great and users don’t perceive any loss of smoothness at all.

object.isBullet is a smoothness killer if you have a lot of ‘bullets’ , at least in my experience, due to its continuous collision detection. [import]uid: 186251 topic_id: 35317 reply_id: 141256[/import]

You said “So I’m animating a number of balls around the screen on an enterframe listener, making sure they dont overlap the screen edges and reversing their direction if so.”

I don’t know exactly what you are doing with them, but could you not put some chunky walls outside the edge of the screen, and attach static physics bodies to them? Then use linear / angular impulses on your ball objects to move them around and let the physics engine handle the reversing directions etc?

If the walls are thick enough then your objects shouldn’t go through them unless they are going super fast, and it saves you having to manually calculate the directions. [import]uid: 84115 topic_id: 35317 reply_id: 141238[/import]

I’ve noticed that if you have a lot of ‘balls’ and use an enterframe listener, then occasionally they will pass thru even static barriers, especially if you have everything set to 60 fps.

To remove those occasionals, I reduced physics.setPositionIterations and physics.setVelocityIterations.
And use an timer.performWithDelay( 5 or even 10) instead of enterframe to handle movement and reverse direction on screen edges
And this is using linearImpulse triggered by explosions and looping thru the balls table to check for distance from explosion - with allowable distance set to half the screen width.

And things run great and users don’t perceive any loss of smoothness at all.

object.isBullet is a smoothness killer if you have a lot of ‘bullets’ , at least in my experience, due to its continuous collision detection. [import]uid: 186251 topic_id: 35317 reply_id: 141256[/import]