OnColission game locks up for few seconds.

Topics: Developer Forum, User Forum
Nov 14, 2012 at 12:28 PM
Edited Nov 14, 2012 at 12:29 PM

Hey people, here is my code for an object for my game that is an implementation of a bomb that explodes on contact.


    class Bomb : GameObject
        public Bomb(Vector2 pos)
            Body = BodyFactory.CreateRectangle(PROTO.GetWorld(), 0.10f, 0.02f, 1);
            Shape = new PolygonShape(PolygonTools.CreateRectangle(0.05f, 0.01f), 1);
            Fixture = Body.CreateFixture(Shape);
            Body.Position = pos;
            Type = BodyType.Dynamic;
            Body.OnCollision += Body_OnCollision;

        bool Body_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact)
            Vector2 worldPosition = Body.Position;
            Vector2 min = worldPosition - new Vector2(5, 5);
            Vector2 max = worldPosition + new Vector2(5, 5);

            AABB aabb = new AABB(ref min, ref max);
                fixture =>
                    Vector2 fv = fixture.Body.Position - worldPosition;
                    fv *= 5;
                    fixture.Body.ApplyLinearImpulse(ref fv);
                    return true;
                }, ref aabb);
            return false;


So what happens is that when my bomb hits the "floor" its fine, no lockup the impulse gets applied to the objects fine as seen here http://phmp.net/?di=313528995174 and here http://phmp.net/?di=613528995186


However when my bomb collides with the circle, it freezes up for few seconds and i get this: http://phmp.net/?di=113528995196


This is the code used to create my circle


Body body = BodyFactory.CreateBody(world, worldPosition);
                body.BodyType = BodyType.Dynamic;
                Random rand = new Random();
                CircleShape shape = new CircleShape(.5f, 5f);
                Fixture fixture = body.CreateFixture(shape);

Any help would be really appreciated, this is doing my head in.
Nov 15, 2012 at 7:56 AM

It seems the lockup happens AFTER  the collision method and not during it. It seems that something holds up the thread. :/