如何让我的身体无视重力(AndEngine)? [英] How do I make a body ignore gravity (AndEngine)?

查看:235
本文介绍了如何让我的身体无视重力(AndEngine)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个精灵(带主体),跳来跳去的情景。它需要不受重力,而且还能够碰撞在现场的其他机构。这意味着我不能使用的运动体。我想:

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()));

这篇关于如何让我的身体无视重力(AndEngine)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆