Having problems using box2D to detect "changing floors"

Anything libgdx related goes here!

Having problems using box2D to detect "changing floors"

Postby BambooBandit » Thu Sep 12, 2019 6:46 pm

I'm trying to detect if a player is changing floors with box2d bodies. But, no matter what approach I take, it doesn't seem possible.

My first instinct was to have a lower sensor and an upper sensor depicted here, so when you are in the lower sensor and hit the upper, you will now be in the upper floor and vis versa.

The problem is, if you walk through them such as the arrows, sometimes contact is not ordered correctly, so it'll say I walked through body 2 THEN 1, which is obviously not correct. So using the two sensor approach doesn't work. The problem with moving the sensors apart is that if you are walking fast enough, the problem can still occur.

Then some people told me to try to cache the collisions, and sort them based on their contact points. Great idea, but sensors don't have contact points. So what if we made them not sensors, and canceled the collisions in preSolve()? Then we can manually call beginContact() but endContact() will not be able to be used, which seems essential to the problem.

Now I can't think of where else to turn.
Posts: 1
Joined: Thu Sep 12, 2019 6:42 pm

Return to Libgdx

Who is online

Users browsing this forum: No registered users and 1 guest