0
votes

I have 2 static bodies, one on top of another.
When I switch the top one to dynamic, it sinks into the static for a second before recovering.

_boxBody->SetType(b2_dynamicBody);
_boxBody->SetAwake(true);

Why does this happen? And how can I prevent it? Very annoying.

1

1 Answers

0
votes

This is probably because static bodies do not collide, so there are no contacts between them until one becomes dynamic. Unfortunately it takes one time step for a contact to be established, and in that time step gravity also has a chance to act.

You might be able to avoid this by making the gravity scale of the dynamic body zero for the first step, but I think a better way would be to call Refilter on the fixtures of the dynamic body before stepping.

for (b2Fixture* f = body->GetFixtureList(); f; f = f->GetNext())
    f->Refilter();

(I haven't actually tried this myself, but I think that's what this Refilter function is for.)