0
\$\begingroup\$

I'm using Box2D and I am putting edge tiles as b2Bodies so that the tile world can have physics:

enter image description here

The problem is that there are 3 b2_kinematic bodies under the player right beside each other.

Every so often, he gets stuck like in this image (as if there were a very very small slope) and the player box gets stuck. I have to move him back a little to overcome it.

The player has fixed rotation which is what also causes this.

I'm not sure how to fix this.

Any ideas?

Thanks

\$\endgroup\$
3
\$\begingroup\$

The problem you're having is that the player box is getting caught up on those 'side' edges of the tiled physics objects you're using.

The usual advice for this sort of situation is to not create your ground by making a lot of boxes which are placed next to each other. Instead, make just one wide rectangle which covers that whole ground section.

You really don't want your collision mesh to have any edges which the player shouldn't be able to bump against; all they'll do is cause this sort of problem.

\$\endgroup\$
  • \$\begingroup\$ Given that I have a std vector of Rect, how could I sort them and get the rectangles I need with the right size? \$\endgroup\$ – jmasterx Jan 7 '14 at 4:31
  • \$\begingroup\$ even better: use edge chain shapes for ground collisions as discussed in the box2d manual \$\endgroup\$ – LearnCocos2D Jan 7 '14 at 8:44
  • \$\begingroup\$ This article gives a good overview of this situation and several solutions that can be used to resolve it. \$\endgroup\$ – NoobsArePeople2 Jan 7 '14 at 20:43
0
\$\begingroup\$

Your box2d bodies are overlapping, which may cause this behavior. Try removing the overlap, by making your bodies a little smaller.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.