Turn off collision

Feb 18, 2011 at 10:47 PM

I'm not sure if you can do this. But can you turn off collision unless the object is a certain distance away from another object?

So nothing collides outside of a radius from a player object.

Will this optimize the PhysicsEngine more or will it actually slow it down?

Feb 19, 2011 at 1:00 AM

The engine does this already. It is called a broad phase and uses a highly optimized tree based algorithm to determine if fixtures can collide or not. When fixtures come close to each other, we check if they touch each other.

Feb 19, 2011 at 3:13 AM

but is it possible to turn off all checks when its off screen for gameplay reasons?

Feb 19, 2011 at 8:39 PM

Yes, indeed it is.

If you create an AABB that is the same size as the screen, then you can iterate all the fixtures that are outside the AABB and disable them (body.Enabled = false). That would take them out of the physics simulation until you re-enable them.

Feb 23, 2011 at 6:50 PM

Sorry, but wouldn't that disable movement?

Feb 24, 2011 at 8:16 AM

In this case you would want to use collision categories. Just set your fixture CollisionFilter's CollisionCategory and CollidesWith to Category.None