Distinguish vertical and horizontal collisions

I’ve been thinking about it for some time now.

Is it possible to to detect whether object1 collided with object2  horizontally or vertically?

I want Corona detect if two objects collide like this:

or like this:

Would be really useful to me.

I’ve been searching around the internet if anyone has done this already, but no luck so far.

Also I’ve thought about attaching another shape on the top of an object or on its side, and then checking collision with those shapes, but that wouldn’t be too convenient for my game.

Can’t think of anything else right now.

Any ideas?

Ok, I got it!

If anyone else needs to know, here’s how you do it:

You compare event.object1.contentBounds   and event.object2.contentBounds.

if(event.object1.contentBounds.yMax \> event.object2.contentBounds.yMin) then print("collided horizontally") else print("collided vertically") end

If your character hits something when he lands on it (vertically) or if your character walks to that something (horizontally).

Ok, I got it!

If anyone else needs to know, here’s how you do it:

You compare event.object1.contentBounds   and event.object2.contentBounds.

if(event.object1.contentBounds.yMax \> event.object2.contentBounds.yMin) then print("collided horizontally") else print("collided vertically") end

If your character hits something when he lands on it (vertically) or if your character walks to that something (horizontally).