This project has moved and is read-only. For the latest updates, please go here.

Dynamic Body is sometimes stoped when in contact with a sensor.

Oct 7, 2011 at 5:05 PM

Hey again ;)

After solving my previous problem I have another pesky thing that doesn't want to get solved. I am writing a normal platformer game(2d view, player walking, jumping on tiles etc).Basicly what started to happen was player stopping DURING walking on the ground. I couldn't figure out why this was happening for couple days, but today I was able to find out the reason for it, which is already over half of success. The problem were sensors who were on the course of the player. Player when walking on the floor is sometimes walking through some objects that have static bodies, and sensor parameter set to true. Once that occurs, something happens backstage and the physics engine is getting confused, and (not always, but pretty often) it stops my player. I keep the button to move left/right pressed down, the animation is still running, but the player is not moving as if he walked into a wall(but he didn't, he has open space in front of him).

This happens most often DURING the contact with a sensor, but on rare ocasions it happens even after the contact ended with the object who was sensor. Once I removed bodies for those sensor objects and just left the sprites, the stopping was not happening anymore and the player was walking normally. But with those objects having static bodies and sensor parameter to true, the engine is starting to act strange.

Is it some kind of a bug of Box2D, or am I doing something wrong here/am missing something?



Oct 10, 2011 at 4:58 PM
Edited Oct 10, 2011 at 4:58 PM

Hi again guys. I'm still working on my problem, got a bit further in pointing out the source of the problem. Seems it has nothing to do with sensors after all, but tiles.

I was able to use the XNA Renderer Helper, that is showing the bodies and thanks to that I was able to notice, that everytime player gets stuck it's right on the border of one tile and the next. It seems almost as if the body of the player was not moved up enough by the physics engine, and the tile next to it is in colision with the bottom of the players body(even if it's 1 px).

I uploaded couple images to show how it looks. I appologies that the images are not bigger, but I have to keep it that way due to legal reasons. It's not important however to visualisation of the problem, as it's perfeclty well visable on these images.

First 3 images you see players body in the top right corner(grey), and the tiles with their bodies(green border). Last picture the situation is reversed to show it's happening from both sides.

Once I get stuck with in a position I can't move past it UNLESS I jump over it. Also, this problem is TOTALY random, which is even more frustrating. Sometimes you can work back and forth, and no problem, and then bam, you got stuck. Then you jump over it, go back, and we go back to square one, it might stuck but he might walk past it fine.

Oct 11, 2011 at 9:28 AM

yes this is a known issue.

to solve it you have to loop trough your tilemap and look if there are tiles on the top, left, bottom, right side and connect them and make a big poygon out of it.

kinda like