简体   繁体   中英

Reflecting a body with same speed in Box2d after collision AndEngine

Is there any way to reflect a physics body in Box2d in AndEngine with the same speed after collision. Suppose if a ball hits the wall with speed X and reflects, then the speed after reflecting must be X again. Is that possible? If so please tell me how can I do this.

What you're looking for is the second parameter of

PhysicsFactory.createFixtureDef(pDensity, pElasticity, pFriction)

If you set the restitution coefficient (elasticity) to 1, the body should be perfectly elastic thus having the same speed after it bounces off the wall. That is in theory. In practice, the body will still be losing a little bit of momentum due to the limited precision of calculations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM