Saturday, April 21, 2018

box2d - Why might a body suddenly stop while moving on continue platform?


I have a 32x32 sprite and I make some to be platform like this


for (int i = 0; i < 15; i++) {
attachChild(new Ground(32 * i, 200, regPlatform, vertexBufferObjectManager, physicsWorld));
}


And I have another sprite (32x32 also) moving over those platforms (A player object)


attachChild(new Player(10, 10, regPlayer, vertexBufferObjectManager, physicsWorld));

And the physicsWorld connects the player like this (Where move=1 when user click right button, and move=2 when user click left button)


physicsWorld.registerPhysicsConnector(new PhysicsConnector(this, body, true, false) {
if (move == 1) {
body.setLinearVelocity(new Vector2(8, body.getLinearVelocity().y));
} else if (move == 2) {
body.setLinearVelocity(new Vector2(-8, body.getLinearVelocity().y));

}
}

The Player moves smoothly form left to right and reverse. But sometimes, it is blocked. If the player move back a bit, and back again where it is blocked, it isn't blocked any more at the same place.


Anyone has any idea to fix this? Maybe it is a bug of andengine and box2d and I need some trick here? Please help me. (The two sprites above are just normal png with 32x32px)


Player image:


enter image description here


Platform image:


enter image description here



Answer




AndEngine's physics extension is a port of Box2D. And Box2D's faq says this about tile based environments that should be "smooth":



Using many boxes for your terrain may not work well because box-like characters can get snagged on internal corners. A future update to Box2D should allow for smooth motion over edge chains. In general you should avoid using a rectangular character because collision tolerances will still lead to undesirable snagging.


For more information see this post: http://box2d.org/forum/viewtopic.php?f=3&t=3048



Your description sounds like this problem.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...