Collisions with Physics vs without

It seems like physics is a big hit to performance overhead, rather than using a simpler system. Writing a few functions to test for a points intersecting rectangles, or rectangles overlapping, is pretty easy. 

On the other hand, after working with one of these custom systems you start to see limitations. Shapes need to be circles or rectangles. It’s also necessary to create you own systems to check collisions looping through objects. Then there’s the problem of fast moving objects, that move through  an object, don’t generate a collision. 

Physics solves many of the problems above in a quick and easy to use package. It would be really great if there was collision detection system based on physics without the physics! No gravity, no motion or other stuff. Just the collision system. Make an object, set the shape, register it for collisions. 

Since this is isn’t available at the moment, what are the best settings for optimizing physics for use as a 2d collision detection system? Creating all objects as dynamic with isSensor set true? 

Hi @soggybag,

While physics can be a slight performance hit, I don’t find it to be very much unless there’s a vast amount going on in the scene (hundreds of physical objects). For what you describe, there shouldn’t be much of a perceptible performance impact.

That being said, I agree that physics shouldn’t be used unless it’s warranted. Rob Miracle responded to another post yesterday about using physics in a “Tetris” type of game, and how it’s not really necessary. While physics could be used for that in a non-gravity environment with simple linear velocities on the bricks, his point was that it’s not really required because Tetris is essentially a “grid of squares” and you can manage objects using an array.

Anyway, I’m not sure what kind of scenario you’re designing, but there are ways to make physics more efficient, for example:

  1. turn down the velocity and position iterations settings a bit, if you don’t need ultra-sensitive collision detection.

  2. allow bodies to “sleep”, and if you’re not using them for some time, forcibly put them to sleep… or better yet, just make them inactive.

Brent

Hi,

I have a simple ‘game’ now which i just completed. The missing part is the collision. I would like to enable collision detections of a few hundred particles with a few of my sprites.

Pls may i know how i can do this? Will i get a laggy system if i use Physics and use the code from the tiny game tutorial?

Thanks for advice in advance.
ttee

Hello ttee,

A few hundred objects may cause a noticeable performance hit. That’s a lot of physics objects for the engine to process at any one time. If there is another way that you can implement it, so that there are less bodies active at one time, I would suggest doing so.

Of course you can test hundreds of particles and collisions, but I think it may cause issues in the end.

Regards,

Brent

Thanks Brent

Hi @soggybag,

While physics can be a slight performance hit, I don’t find it to be very much unless there’s a vast amount going on in the scene (hundreds of physical objects). For what you describe, there shouldn’t be much of a perceptible performance impact.

That being said, I agree that physics shouldn’t be used unless it’s warranted. Rob Miracle responded to another post yesterday about using physics in a “Tetris” type of game, and how it’s not really necessary. While physics could be used for that in a non-gravity environment with simple linear velocities on the bricks, his point was that it’s not really required because Tetris is essentially a “grid of squares” and you can manage objects using an array.

Anyway, I’m not sure what kind of scenario you’re designing, but there are ways to make physics more efficient, for example:

  1. turn down the velocity and position iterations settings a bit, if you don’t need ultra-sensitive collision detection.

  2. allow bodies to “sleep”, and if you’re not using them for some time, forcibly put them to sleep… or better yet, just make them inactive.

Brent

Hi,

I have a simple ‘game’ now which i just completed. The missing part is the collision. I would like to enable collision detections of a few hundred particles with a few of my sprites.

Pls may i know how i can do this? Will i get a laggy system if i use Physics and use the code from the tiny game tutorial?

Thanks for advice in advance.
ttee

Hello ttee,

A few hundred objects may cause a noticeable performance hit. That’s a lot of physics objects for the engine to process at any one time. If there is another way that you can implement it, so that there are less bodies active at one time, I would suggest doing so.

Of course you can test hundreds of particles and collisions, but I think it may cause issues in the end.

Regards,

Brent

Thanks Brent