我有一个精灵(带主体),跳来跳去的情景。它需要不受重力,而且还能够碰撞在现场的其他机构。这意味着我不能使用的运动体。我想:
I have a sprite (with a body) that bounces around the scene. It needs to be unaffected by gravity, but also able to collide with other bodies on the scene. This means I cannot use a kinematic body. I tried:
body = PhysicsFactory.createCircleBody(mPhysicsWorld, this, BodyType.DynamicBody, PhysicsFactory.createFixtureDef(.5f, .5f, .5f));
MassData md = new MassData();
md.mass=0;
body.setMassData(md);
mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(this, body, true, true));
与我FixtureDef不同的值,但似乎没有任何工作。我的身体仍然落在现场的底部,坐在那里。我看到了一些有关应用相等,方向相反的力量。如果我的引力是地球的默认,这是一个可行的选择,究竟我会怎么做呢?还是有更好的方法来从引力场中删除此身,仍然有它与其他动态物体互动?
with different values for my FixtureDef, but nothing seemed to work. My body still falls to the bottom of the scene and sits there. I saw something about applying an equal and opposite force. If my gravitational force is the earth default and this is a viable option, how exactly would I do it? Or is there a better way to remove this body from the gravitational field and still have it interact with other dynamic bodies?
推荐答案
我不知道是什么版本的Box2D的包括在AndEngine的当前版本,但你可以尝试 body.setGravityScale(0) ;
I am not sure what version of Box2D is included in the current version of AndEngine, but you could try body.setGravityScale(0);
如果不工作,你必须把它放到OnUpdate中:
If that does not work, you'll have to put this in onUpdate:
body.applyForce(new Vector2(0,-SensorManager.GRAVITY_EARTH), new Vector2(body.getWorldCenter()));
相关推荐
最新文章