gpt4 book ai didi

java - Libgdx Box2D Velocity 不够快

转载 作者:行者123 更新时间:2023-12-03 23:14:21 29 4
gpt4 key购买 nike

我有一个我想快速移动的矩形,但出于某种原因,我使用的更快速度似乎仍然很慢。我究竟做错了什么?我还从上面掉了一个圆圈到一个表面上,即使我用重力玩它也很艰难,它像气球一样落下......

一些声明

float velocity = 10000000f;
static final float BOX_STEP=1/60f;
static final int BOX_VELOCITY_ITERATIONS=6;
static final int BOX_POSITION_ITERATIONS=2;

重力,什么都试过了,他们似乎都很烂

world = new World(new Vector2(0, -50), true);

我的物体正在移动的地面

    //ground
BodyDef groundBodyDef =new BodyDef();
groundBodyDef.position.set(new Vector2(0, camera.viewportHeight * .08f));
Body groundBody = world.createBody(groundBodyDef);
PolygonShape groundBox = new PolygonShape();
groundBox.setAsBox((camera.viewportWidth) * 2, camera.viewportHeight * .08f);
groundBody.createFixture(groundBox, 0.0f);

然后这是我的对象:

    //ball
bodyDef = new BodyDef();
bodyDef.type = BodyType.DynamicBody;
bodyDef.position.set(new Vector2(camera.viewportWidth * .2f, camera.viewportHeight * .75f));
body = world.createBody(bodyDef);
CircleShape dynamicCircle = new CircleShape();
dynamicCircle.setRadius(camera.viewportWidth * .035f);
FixtureDef fixtureDef = new FixtureDef();
fixtureDef.shape = dynamicCircle;
fixtureDef.density = 0.5f;
fixtureDef.friction = 0.5f;
fixtureDef.restitution = 0.8f;
body.createFixture(fixtureDef);
body.setLinearVelocity(0,-100);

//slime boy
BodyDef bodyBoxDef = new BodyDef();
bodyBoxDef.type = BodyType.DynamicBody;
bodyBoxDef.position.set(new Vector2(camera.viewportWidth * .08f,camera.viewportHeight * .191f));
bodyBox = world.createBody(bodyBoxDef);
PolygonShape slimeBox = new PolygonShape();
slimeBox.setAsBox(camera.viewportWidth * .04f, camera.viewportHeight * .03f);
FixtureDef fixtureSlimeDef = new FixtureDef();
fixtureSlimeDef.shape = slimeBox;
fixtureSlimeDef.density = 1.0f;
fixtureSlimeDef.friction = 0.0f;
fixtureSlimeDef.restitution = 0.0f;
bodyBox.createFixture(fixtureSlimeDef);

debugRenderer = new Box2DDebugRenderer();

body.applyTorque(1000000000);
bodyBox.setFixedRotation(true);
bodyBox.setBullet(true);

有人建议加快这方面的所有运动吗?

我一直在使用 1280 x 720 的屏幕,但我从其他来源看到越小越好,所以我缩小到 640 x 260,但仍然不是我想要的性能。我到底应该多小?

最佳答案

来自Box2d Manual (第 2.2 节):

Box2D is tuned for meters, kilograms, and seconds. So you can consider the extents to be in meters. Box2D generally works best when objects are the size of typical real world objects. For example, a barrel is about 1 meter tall. Due to the limitations of floating point arithmetic, using Box2D to model the movement of glaciers or dust particles is not a good idea.

参见 https://stackoverflow.com/a/4556714/960524

关于java - Libgdx Box2D Velocity 不够快,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17701142/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com