Hi, everyone, I am having a small issue in which my character seems to gets stuck at certain points of the map. They can keep moving by jumping and then pressing left or right, but it seems that the tiles have a slight offset of 1px that causes the player to get stuck. What can I do about this?
What do you mean by “slight offset”? Which game are you working on now? How does the character get stuck?
It is the same game I have been working on for a while now. I am not 100% sure if the problem is due to a slight offset with the tiles.
The character gets stuck occasionally on the floor. For instance, picture it this way:
If someone is walking and they encounter stairs, they will not progress until they lift one leg.
Unfortunately, my character is not capable of such actions on its own and requires someone to make him jump over it.
Please tell me if this is still confusing.
Sounds like you assembled your platforms/floors from individual physics bodies side-by-side? If so, that’s prone to cause the occasional sticking you describe. Basically, although the two bodies might be touching, there’s still a seam and a sharp corner where each one meets (assuming they’re rectangular). When another body tries to move/coast/roll across that, Box2D sometimes makes that body snag a bit on the seam between the two parts.
Ideally, if you have a long shape or span of ground, you “draw” it from one physics body like a chain/edge shape or a larger rectangle. That will both prevent the sticking and it’s more efficient on the physics engine (fewer bodies in a simulation is always better than more bodies).
Brent
How would I go about achieving this? I mean implementation wise, the current way my map is programmed is based on values inputted on Tiled such as physicsBody and isSensor.
What do you mean by “slight offset”? Which game are you working on now? How does the character get stuck?
It is the same game I have been working on for a while now. I am not 100% sure if the problem is due to a slight offset with the tiles.
The character gets stuck occasionally on the floor. For instance, picture it this way:
If someone is walking and they encounter stairs, they will not progress until they lift one leg.
Unfortunately, my character is not capable of such actions on its own and requires someone to make him jump over it.
Please tell me if this is still confusing.
Sounds like you assembled your platforms/floors from individual physics bodies side-by-side? If so, that’s prone to cause the occasional sticking you describe. Basically, although the two bodies might be touching, there’s still a seam and a sharp corner where each one meets (assuming they’re rectangular). When another body tries to move/coast/roll across that, Box2D sometimes makes that body snag a bit on the seam between the two parts.
Ideally, if you have a long shape or span of ground, you “draw” it from one physics body like a chain/edge shape or a larger rectangle. That will both prevent the sticking and it’s more efficient on the physics engine (fewer bodies in a simulation is always better than more bodies).
Brent
How would I go about achieving this? I mean implementation wise, the current way my map is programmed is based on values inputted on Tiled such as physicsBody and isSensor.