简体   繁体   English

碰撞AndEngine后在Box2d中以相同速度反射物体

[英]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. 有什么方法可以在碰撞后以相同的速度在AndEngine的Box2d中反映物理物体。 Suppose if a ball hits the wall with speed X and reflects, then the speed after reflecting must be X again. 假设如果球以速度X撞击墙壁并反射,那么反射后的速度必须再次为X。 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. 如果将恢复系数(弹性)设置为1,则主体应该是完全弹性的,因此从墙反弹后的速度相同。 That is in theory. 从理论上讲。 In practice, the body will still be losing a little bit of momentum due to the limited precision of calculations. 实际上,由于计算精度有限,身体仍然会失去一点动量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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