简体   繁体   English

增加重量时,andengine Box2D物理机体不旋转

[英]Andengine Box2D physics body is not rotating when increase weight

Andengine Box2D physics body is not rotating when increase weight otherwise its perfectly rotating.I am making a game in which the player can throw the bomb, when the player throws the bomb with bombsBody's natural weight its rotating perfectly but when i increase the weight of bomb the bomb does not rotate.im stuck here..plz help. Andengine Box2D物理物体在增加重量时不会旋转,否则会完美地旋转。我正在制作一个游戏,玩家可以投掷炸弹,当玩家用炸弹投掷炸弹时,身体的自然重量会完美旋转,但是当我增加炸弹的重量时炸弹不旋转。我被困在这里。 Thank you. 谢谢。

if (bomb)           
{
    mScene.detachChild(target);
    target = null;      
    bombFire = new Sprite(mBall2.getX()+mBall2.getWidth()/2,mBall2.getY(),bombFireRegion);
    mScene.attachChild(bombFire);
    bombBody = PhysicsFactory.createCircleBody(mPhysicsWorld, bombFire,BodyType.DynamicBody, bombFixDef);
    bombBody.setMassData(bombMass);
    mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(bombFire, bombBody, true, true));               
    Vector2 v = new Vector2((xpt-mBall2.getX()),(ypt-mBall2.getY()));
    bombBody.applyLinearImpulse(v,bombBody.getWorldCenter());
}

Changing the mass of an existing body is best done by scaling the existing massData of that body. 更改现有实体的质量最好通过缩放该实体的现有massData来完成。 This keeps the center of mass in the right place and also ensures that the mass and rotational inertia match correctly. 这样可以将质心保持在正确的位置,并确保质量和转动惯量正确匹配。

b2MassData massData;
body->GetMassData(&massData);

float scaleFactor = desiredMass / massData.mass;
massData.mass *= scaleFactor;
massData.I *= scaleFactor;

body->SetMassData(&massData);

One thing to be aware of is that this does not affect the density of the fixtures on the body. 要注意的一件事是,这不会影响人体固定装置的密度。 If you add or remove any fixtures from the body after this, the mass data will be recalculated from the fixtures, not from your mass data. 如果在此之后从车身添加或移除任何固定装置,则将从固定装置而不是从质量数据重新计算质量数据。 So you would have to do this again after changing fixtures to restore your desired mass. 因此,您必须在更换固定装置后再次执行此操作,以恢复所需的质量。

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

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