gpt4 book ai didi

java - Box2d Edgeshape 不旋转

转载 作者:行者123 更新时间:2023-11-30 06:24:07 28 4
gpt4 key购买 nike

我正在使用 Libgdx 的 box2d 端口。我正在创建一个边缘形状,但它不会在与其他多边形碰撞时旋转。这是为什么?

这是我设置边缘形状的代码。

float x = 3;
float y = 10;
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.DynamicBody;
bodyDef.position.set(x, y);

Body body = this.world.createBody(bodyDef);
MassData massdata = new MassData();
massdata.center.set(1,1);
massdata.mass = 10;
body.setMassData(massdata);

FixtureDef fixtureDef = new FixtureDef();
EdgeShape shape = new EdgeShape();
shape.set(0, 0, 2, 2);
fixtureDef.shape= shape;
fixtureDef.friction = 1;
fixtureDef.restitution = .5f;
fixtureDef.density = 10;
body.createFixture(fixtureDef);

最佳答案

那是因为 Box2D 中的边缘形状旨在创建静态场景。由于动力学原因,它根本无法移动。我想运动学会起作用。这是合乎逻辑的,因为 EdgeShape 没有质量,因为它没有表面(或者体积,如果您将 2D 世界视为具有固定深度的 3D)。

这是手册中的一段摘录,它证实了我最初的想法:

Edge shapes are line segments. These are provided to assist in making a free-form static environment for your game. A major limitation of edge shapes is that they can collide with circles and polygons but not with themselves. The collision algorithms used by Box2D require that at least one of two colliding shapes have volume. Edge shapes have no volume, so edge-edge collision is not possible.

关于java - Box2d Edgeshape 不旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17394621/

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