Jan 14, 2014 at 2:07 PM
Edited Jan 14, 2014 at 2:08 PM
I have two different types of animals(bodies) in my game, wolfs and sheeps.
If a wolf touches a sheep, the wolf eats the sheep and the wolf gets 100 points per sheep. In addition, the sheep body must get disabled and removed, because it should not be possible that more than one wolf can eat the same sheep.
I made two different collision categories:
In the wolf class, I check if a wolf collides with a sheep:
if (fixtureB.CollisionCategories == Category.Cat27)
//I want to disable the sheep's body so that this sheep can't collide with another wolf
if (fixtureB.Body.Enabled == true)
fixtureB.Body.Enabled = false;
But I always get an error message in this line of the Farseer's Contact.cs class if I disable the body:
An exception of type 'System.NullReferenceException' occurred in FarseerPhysicsXNA.DLL but was not handled in user code
//Reverse the order of the reported fixtures. The first fixture is always the one that the user subscribed to.
if (FixtureB.OnCollision != null)
Enabled = FixtureB.OnCollision(FixtureB, FixtureA, this);
What is wrong? Isn't it possible to disable a body during a world step?
How can I solve the problem? I need to disable and remove a sheep's body so it can't collide again with another wolf.