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

Collision occurs, when it shouldn't

Mar 3, 2012 at 1:52 PM

Hi, everyone, I'm developing a simple shoot'em up game using Farseer 3.3. Thats my second game ever, so sorry if im asking about some basics. I have a problem when it comes to collisions. Basically everything is working fine except one thing, Player collides with his own bullets. It's really strange for me since i set collisionCategories and collisionWith for bullets not to collide with player.

In class Player:

Body.CollisionCategories = Category.Cat2;
Body.CollidesWith = Category.Cat1 | Category.Cat4 | Category.Cat5;

In class Beam:

if (isStartedByPlayer)
    Body.CollisionCategories = Category.Cat3;
    Body.CollidesWith = Category.Cat4;
    Body.CollisionCategories = Category.Cat5;
    Body.CollidesWith = Category.Cat2;

where isStartedByPlayer is always true, by now. I could use IgnoreCCD() or something like this, and that solves my problem, but i'm planning to use the same class to make enemy bullets easily by setting only collisionCategories and bullet direction. What is happening?

My first thought was Body.OnCollision += OnHit; when OnHit() deploys both bullet and its target ignores category collisions but it would be rather stupid.


Mar 4, 2012 at 6:49 PM

Just a quick read but are you modifying the world inside the Step() method (collision callbacks are called from there). This is not recommended and might produce all kinds of weird behaviour. Just something I've seen on the box2D forums - don't know if it relates to your situation.

Mar 5, 2012 at 5:12 AM

For this senerio I would use something like


in the constructor for the bullet. as for the category stuff, I haven't had much luck. I found 

            bulletFixture.CollisionGroup = -1;
Is also good to set for your bullets. It won't help for your player collision but it'll make it so that your bullets don't collide with other bullets.