A body position cannot be set after a collision.

Hi,
I've got a very annoying problem with b2body#SetPosition() method, right after the collision occurs on the body.
The method just doesn't work until a couple of world steps are passed.
The only way I found to work around this issue is to set up a timer which will call this method, until body's position is what I need.
But it appears to be very clumsy.
So, the question is: is it possible to force the body to change its position despite any contacts and other circumstances?

p.s. I'm using box2d 2.1a.

regards, Konstantin.
I could be wrong here, but in previous versions anyway (before the fixtures etc) you couldn't move\remove objects during a step because the world was locked. I.e. check b2world.IsLocked();

There was also something in the documentation about your b2ContactListener class generating multiple BeginContact events etc.

Few solutions:


Make a contact list, i.e. a list of contacts.
A vector<b2Contact> won't work, as some of the variables within the contact will have expired after the step. Instead make a list manually, or check your collision conditions and call the appropriate functions telling them to do their business on the next onFrame().

On each frame, instead of checking actual collisions, use the m_world.QueryAABB() function.
It's not as slow as you might think either.

Or last resort, just use a little trig to check the distance between 2 things if for example both objects are say roundish, and the angle won't matter much.

I always worry that I'm adding too many conditions or slowing down the contact listener, but it seems to soldier on anyway at a decent speed - try a few things 🙂
Quote:
you couldn't move\remove objects during a step because the world was locked. I.e. check b2world.IsLocked();

Yes, you're right.
But I've already found it out.
Anyway, thanks for the reply 🙂
Heh, I found this right afterwards too:
viewtopic.php?f=3&t=7731

Glad you got it sorted though 🙂

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