Polygon bodies don't colide

Topics: Developer Forum
Jul 6, 2012 at 12:30 AM
Edited Jul 6, 2012 at 12:32 AM

Hi guys,

Using FPE for the first time and it's really cool :)

However, I'm kind of stuck with the following, hope you can see what I am missing. I have two 'Agent' bodies and x 'Food' bodies.  The Agents call OnCollision with the Food, but not with eachother, i.e. Agent collide with Agent.

I have the following:

 

//Loading and using the texture works as expected
Texture = Assets.TextureFromVertices(verts, MaterialType.Dots, Color, 1f);                       

//The agents show as expected, but doesn't collide with other Agent
AgentBody = BodyFactory.CreateBody(World, position); 
PolygonShape agentShape = new PolygonShape(verts, 1f);   
AgentBody.CreateFixture(agentShape);     
AgentBody.CollisionCategories = Category.Agent;            
AgentBody.CollidesWith = Category.All; 
AgentBody.BodyType = BodyType.Dynamic;
AgentBody.OnCollision += AgentCollision;

...

//Gets called when colliding with Food
private bool AgentCollision(Fixture a, Fixture b, Contact contact) {
    if(b.UserData is Agent)
         Console.WriteLine("Agent collision");
}

 

Cheers

Anders

Jul 7, 2012 at 11:24 AM

Do you actually set the UserData to Agent - because you don't in the AgentBody.CreateFixture.

Jul 7, 2012 at 2:37 PM

No you're right I missed that. But AgentCollision doesn't get called at all. 

Jul 7, 2012 at 10:08 PM

Does it get called if you change Agent.CollisionCategories=Category.Cat1?

I'm not sure even how Category.Agent can even get compiled or what it actually evaluates to.

Jul 7, 2012 at 11:13 PM

No same thing.

Category.Agent is just a Category.Cat1 that has been renamed.

Only progress so far is, that if I spawn a lot of agents AgentCollision gets called a few times during the first couple of game loops.

Jul 7, 2012 at 11:59 PM

You might have more luck with a BeginContact handler and check the contact properties for the fixtures. I myself have never had problems with it.

Jul 10, 2012 at 4:27 PM

Thanks for your input Jerry. It seems it works now, but not sure what have chaged though, the code is the same as the above.

Cheers

Anders

Jul 10, 2012 at 6:22 PM

You can try putting a conditional code breakpoint in Contact.Update() and see why it's not calling the OnCollision handler but it's weird since OnBeginContact is just after...