Detecting where (top,bottom,left,right) a collision occurs

May 14, 2009 at 4:51 PM

Hey guys, I have the shell of my engine working quite well now but I am having trouble with one small thing. I need a way to check which side of my player is colliding with a platform or enemy. For example, right now I have the engine loop through each arbiter to check if the player is colliding with the terrain and whatnot using tags. The problem is when you run up to a wall- the player is technically colliding with the terrain and therefore they are able to jump up the wall multiple times. Another problem arises when deciding whether the player killed an enemy or the enemy killed the player - I want to check if the bottom of the player collided with the top of the enemy to kill it and for every other situation the enemy would kill the player. 

In summary - I need a way to define what verticies are "feet" and "head" etc. 

Also one more quick question: should geometry tags be strings? thats the way im using them now and it seems to be working fine but when I build I get a warning saying I should cast the tag as a string or it may not work properly.

Thanks a lot!

May 15, 2009 at 8:47 AM

in OnCollision() just sum up all Normals of the Contacts and check them against an angle

see this thread:

especially this section:

           Vector2 normal = Vector2.Zero;

            foreach( var contact in contactList )
                normal += contact.Normal;

            double minCrossP = normal.X * MinVector.Y - normal.Y * MinVector.X;
            double maxCrossP = normal.X * MaxVector.Y - normal.Y * MaxVector.X;

            bool isOnGround = minCrossP >= 0 && maxCrossP <= 0;