Missing collision ending. What to do? I really need it.

Hi,

I'm moving my player with SetVelocity whenever my player hitbox is not currently in contact with a left or right wall (90 degree angles). This is to prevent the player from being stuck to the wall if I apply a velocity when he is already in contact with it. So I have set up a few bools like this:

bool touchingRightWall;
bool touchingLeftWall;

In my player class, I override the beginContact and endContact methods and set these bools to true or false depending on the collision normal.

It works great most of the time, but problem is- sometimes the endContact won't seem to be called and therefore my player will think it's still stuck to a wall and it will just not work out the way I intend it to.

I am aware of this stated somewhere: "However, you might miss some contacts because continuous physics leads to sub-stepping. Additionally you may receive multiple callbacks for the same contact in a single time step. You should strive to make your callbacks efficient because there may be many callbacks per time step. ".

But I can't figure out what is causing this or how to solve it. Other solutions for moving the player without making him stuck to the wall are welcome.

Thanks
That quote is not related to the problem you are having.

I recommend you do some further debugging or create an example for the testbed.
If the quote wasn't relevant it's a problem on my end. It seems to be triggered when moving fast back and forth over 90 degree corners.

The hitbox is a square. I know it's not recommended but I'm not sure if its shape is causing this?
I don't think the shape matters. It is possible there is a bug in Box2D, but unlikely if you are using the latest in SVN.
-Oscar- wrote:
I ... set these bools to true or false depending on the collision normal.

In which case the shape of the fixture might actually matter. Two things I would suggest for keeping track of what an object is touching:
1. keep a count of how many begin/end contacts you got and increment/decrement this, not just a simple bool
2. don't use the collision normal from box2d for this kind of decision-making
irresistible force wrote:
-Oscar- wrote:
I ... set these bools to true or false depending on the collision normal.

In which case the shape of the fixture might actually matter. Two things I would suggest for keeping track of what an object is touching:
1. keep a count of how many begin/end contacts you got and increment/decrement this, not just a simple bool
2. don't use the collision normal from box2d for this kind of decision-making


I have abandoned the idea to use the normals to prevent the player from getting stuck to the wall. I still can't think of a suitable solution however, if you have any suggestion please share.

The problem occurs when I apply a force to the player when he is already against a wall.

Original thread: https://box2d.org/forum/viewtopic.php?t=6495