JME-Jbullet物理题

发布于 2024-08-25 11:17:31 字数 531 浏览 6 评论 0原文

我目前正在使用 JME-Jbullet 物理引擎,但我的地形遇到了问题。

我有 2 个扁平的盒子,一个用于地板,另一个用作坡道。问题如下:

使用以下代码:

Box slope = new Box("Slope", new Vector3f(0, -1, 0), 10f, 0f, 15f);
PhysicsNode pSlope = new PhysicsNode(slope, CollisionShape.ShapeTypes.MESH);
pSlope.setMass(0);
pSlope.getLocalRotation().fromAngleNormalAxis( 0.5f, new Vector3f( 0, 0, -1 ) );

在应用旋转之前,盒子表现正常,如果另一个对象掉落在顶部,则它们会正确碰撞。然而,旋转之后,盒子会旋转,但它的“物理”不会改变,因此当一个物体掉落到看似斜坡的顶部时,它的表现就好像旋转从未发生过一样。

是否有某种方法可以更新斜坡,以便当物体掉落到其上时,它会滑落?

谢谢。

I'm currently playing with the JME-Jbullet physics engine, and having issues with my terrain.

I have 2 flat boxes, one for the floor, and one to act as a ramp. The issue is as follows:

With the following code:

Box slope = new Box("Slope", new Vector3f(0, -1, 0), 10f, 0f, 15f);
PhysicsNode pSlope = new PhysicsNode(slope, CollisionShape.ShapeTypes.MESH);
pSlope.setMass(0);
pSlope.getLocalRotation().fromAngleNormalAxis( 0.5f, new Vector3f( 0, 0, -1 ) );

Before the rotation is applied, the box acts as normal, if another object is dropped on top, then they collide correctly. After the rotation however, the box is rotated, but its "Physics" doesn't change, so when an object is dropped ontop of what appears to be the ramp, it is acting as though the rotation never happened.

Is there some way to update the ramp so that when an object is dropped on to it, it slides down?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一个人的夜不怕黑 2024-09-01 11:17:32

您还记得在 update 方法中更新物理世界吗?

public void update(float tpf) {
    super.update(tpf);
    pSpace.update(tpf);
}

其中 pSpace 来自 PhysicsSpace pSpace=PhysicsSpace.getPhysicsSpace();

are you remembering to update the physics world in your update method?

public void update(float tpf) {
    super.update(tpf);
    pSpace.update(tpf);
}

where pSpace comes from PhysicsSpace pSpace=PhysicsSpace.getPhysicsSpace();

野侃 2024-09-01 11:17:32

问题出在碰撞形状上。网格是计算碰撞的极其昂贵的形状,据我所知,它在 JME 中还不能正常工作。将其替换为盒子碰撞形状即可解决您的问题。

The problem is in the collision shape. A mesh is an extremely expensive shape to calculate collisions for, and as far as I am aware of not working properly (yet) in JME. Replacing it by a box collision shape will solve your problem.

淑女气质 2024-09-01 11:17:32

javadocs

getLocalTranslation().set() 不设置物理对象位置,使用 setLocalTranslation(),同样适用于 getLocalRotation()

我猜你需要调用 pSlope.setLocalRotation(...) 而不是获取旋转并就地修改它。

As indicated in the javadocs:

getLocalTranslation().set() does not set the physics object location, use setLocalTranslation(), same applies for getLocalRotation()

I would guess from that that you will need to call pSlope.setLocalRotation(...) instead of getting the rotation and modifying it in place.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文