Detect collision from a particular side

Posted by Fabián on Game Development See other posts from Game Development or by Fabián
Published on 2014-06-02T05:56:05Z Indexed on 2014/06/02 9:54 UTC
Read the original article Hit count: 327

Filed under:
|

I'm making a platform sidescrolling game. All I want to do is to detect if my character is on the floor:

function OnCollisionStay (col : Collision){
    if(col.gameObject.tag == "Floor"){
        onFloor = true;
    } else {onFloor = false;}
}
function OnCollisionExit (col : Collision){
    onFloor = false;
}

But I know this isn't the accurate way. If I hit a cube with a "floor" tag, in the air (no matter if with the character's feet or head) I would be able to jump.

Is there a way to use the same box collision to detect if I'm touching something from a specific side?

© Game Development or respective owner

Related posts about unity

Related posts about collision-detection