Reputation: 6931
I am working with Box-2d & AndEngine. I have dynamic body lets say a Plane. I want to moves this continuously with a given velocity. So, I set a linear Velocity to it. I have screen boundary(ground,roof,left & Right Wall) as well. Those are static body. When my plane collides with boundaries one or two times, it's becomes stopped. I apply no gravity to plane. Why plane stopped though it has fixed velocity? Problem: How I move the plane with continuous speed as well as corresponding direction after collide ? After that I want to move it where the user touches on the screen?
Code: create plane
FixtureDef FIXTURE_DEF = PhysicsFactory
.createFixtureDef(1, .5f, 0.5f);
aPlane = new Plane(222, 333, pilotTexures, vbom) {
@Override
protected void onManagedUpdate(float pSecondsElapsed) {
super.onManagedUpdate(pSecondsElapsed);
}
};
planeBody = PhysicsFactory.createBoxBody(this.mPhysicsWorld, aPlane,
BodyType.DynamicBody, FIXTURE_DEF);
mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(
aPlane, planeBody, true, true));
planeBody.setLinearVelocity(DEMO_VELOCITY_X, DEMO_VELOCITY_Y);
attachChild(aPlane);
planeBody.setGravityScale(0);
planeBody.setUserData(PLANE);
Code: create boundary wall
final Rectangle ground = new Rectangle(0, camera_Height - 2,
camera_Width, 2, vbom);
final Rectangle roof = new Rectangle(0, 0, camera_Width, 2, vbom);
final Rectangle left = new Rectangle(0, 0, 2, camera_Height, vbom);
final Rectangle right = new Rectangle(camera_Width - 2, 0, 2,
camera_Height, vbom);
final FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0,
0.5f, 0.5f);
PhysicsFactory.createBoxBody(this.mPhysicsWorld, ground,
BodyType.StaticBody, wallFixtureDef);
Body roofBody = PhysicsFactory.createBoxBody(this.mPhysicsWorld, roof,
BodyType.StaticBody, wallFixtureDef);
roofBody.setUserData(ROOF);
PhysicsFactory.createBoxBody(this.mPhysicsWorld, left,
BodyType.StaticBody, wallFixtureDef);
PhysicsFactory.createBoxBody(this.mPhysicsWorld, right,
BodyType.StaticBody, wallFixtureDef);
attachChild(ground);
attachChild(roof);
attachChild(left);
attachChild(right);
I also create ContactListener, can listen when they collide . To move on finger touched point I also implements IOnSceneTouchListener
Thank in advance.
Upvotes: 0
Views: 256
Reputation: 798
Could you try setting the elasticity of your walls to 1.0f and for regular contact remove the friction,
final FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0,
0.5f, 0.0f);
To,
final FixtureDef wallFixtureDef = PhysicsFactory.createFixtureDef(0,
1.0f, 0.0f);
Hop this helps.
Upvotes: 1