This project has moved and is read-only. For the latest updates, please go here.

Temporarily disable collision for object

Topics: Developer Forum
Apr 16, 2011 at 11:03 PM

Hey. Probably a simple question but I would like to disable all collisions if the player is in a certain state. For example, if the user becomes 'invisible' (collects a power up), I'd like all collisions with the player to be ignored (but any forces are still acting, so the simulation isn't completely disabled). How would I do this? I tried 'Awake' but that just stops the player. Is there a 'Collision enabled' type property I can enable/disable in real time? 


Apr 16, 2011 at 11:11 PM

You can disable the body by using the enabled property.

Apr 16, 2011 at 11:15 PM
Edited Apr 16, 2011 at 11:15 PM

Unless I'm doing something wrong, the body loses all forces that have been applied to it (when Enabled = false). I'd like it to continue on whatever path it was going on (impulse previously applied), but go through any other object rather than bounce off.

Apr 17, 2011 at 12:03 AM

Use a collision filter. Set the collision groups or categories to ignore everything else than the ground.

Apr 17, 2011 at 12:43 AM

I'm trying the following code, just to test it not colliding at all. However, the collision still occurs. Am I using it wrong? Thanks for the help.

foreach (Fixture f in player.FixtureList)
       f.CollisionFilter.CollidesWith = Category.None;


Apr 17, 2011 at 12:50 AM

Collision categories consist of both collideswith and collisioncategory. I would use collision groups if I were you.

Apr 17, 2011 at 1:27 AM
Edited Apr 17, 2011 at 1:38 AM

I tried using Collision Groups but it never seemed to work. I put the player and objects in collision group 5, but they still all collided. Then I came across this post ( and think that's the problem. :(

-EDIT: My bad. I used the method suggested in the link and it worked. At first, I only did it for the ball and forgot to do it for all the other objects. Thanks for the help!