in relation to the normal bug / feacher

Jul 20, 2009 at 9:10 AM
hi i know that the order that the geoms are created is related to the normal angle recived in the onCollison() hander if sometimes the ground can be 90 degress and other times -90. my questions is this. is there any way in the oncollison funtion to determin the order of the geom collideing because if there is i can just *=-1 the angle when needed to get constante results
Jul 20, 2009 at 1:34 PM

Yeah, genbox added the Geom.Id public property especially for this reason (I think). It gets incremented in the Geom constructor, so it should give you the order of creation. Hmmm although I guess you might have a problem if you don't add the geoms to the simulator in the same order that you create them.

If that doesn't work for you, another method is to compare the geom positional difference with the normal direction by using a dot product. EG:

if (Vector2.Dot(geom2.Position - geom1.Position, contacts[0].Normal) > 0) // normal points from geom 1 to geom 2



Jul 20, 2009 at 1:41 PM

Yes there is. But it depends on you.

The OnCollision event is fired for both colliding geometries and the geometry that has registered the event is always the one in the first argument.


//Created first (id 0)
Geom player...;
player.OnCollision += OnCollision;

//Created second (id 1)
Geom ground...;

private void OnCollision(Geom geomA, Geom geomB, ContactList list)

    geomA // <- always the player geometry
    geomB // <- always the other geometry

Problem is that if you register the OnCollision event on both the geometries, then you can't be sure of the order using the arguments. You can however check it by yourself using the < and > operators.


if (geomA < geomB)
    // geomA is newer (created first) because id is smaller