box2dbox2dweb

How to find if top of rectangle collided or not in box2d


I have rectangular player in top down game. I want to find which side(to be specific top of rectangle ) of rectangle is hit by other game objects.


Solution

  • If you want to distinguish between collisions for different parts of your game object, use different fixtures for those parts. So if you want to distinguish between top and bottom for example:

    -----------------
    |               |
    |Top Fixture    |
    |               |
    -----------------
    |               |
    |Bottom Fixture |
    |               |
    -----------------
    

    These could also be sensors (so no physics) as an overlay for your other physics fixtures.