简体   繁体   English

Box2D身体旋转错误

[英]Box2D wrong body rotation

I making a map with Tiled and load all box2d bodies with Box2DMapObjectParser to my world and everything just work fine except one thing. 我使用Tiled制作地图,并将所有具有Box2DMapObjectParser的box2d实体加载到我的世界中,除了一件事情,其他所有东西都工作正常。 I'm using a newer version of Tiled where implemented body rotation. 我使用的是更新版本的Tiled,其中实现了身体旋转。 I'm trying to implement it in Box2DMapObjectParser by myself and this is what I get from it: 我正在尝试自己在Box2DMapObjectParser中实现它,这就是我从中得到的:

Editor: 编辑: 在此处输入图片说明

And the game: 游戏: 在此处输入图片说明

As you can see the right rectangle has a property named Rotation so I can easily get from properties, but I don't know what is wrong with it. 如您所见,右侧矩形具有一个名为Rotation的属性,因此我可以轻松地从这些属性中获取信息,但我不知道它有什么问题。

I set the rotation like this 我这样设定旋转

fixture.getBody().setTransform(fixture.getBody().getPosition(), degree);

where degree is value from editor. degree是编辑的价值。 Anybody have a clues about what am I doing wrong? 有人知道我在做什么错吗? I also tried doing something like 我也尝试做类似的事情

fixture.getBody().setTransform(fixture.getBody().getPosition(), degree*MathUtils.degreesToRadians);

But itsalso sets a wrong rotation. 但是它也设置了错误的旋转。

Tiled rotates rectangle objects by their top-left corner. 平铺将矩形对象的左上角旋转。 Box2D rotates around the position of the body, so the easiest solution is probably to create your box fixture such that the position of the body is in the top-left (if you're using b2PolygonShape::SetAsBox this means passing a center at half the width and half the negative height (since the Y axis is inverted)). Box2D围绕身体的位置旋转,因此最简单的解决方案可能是创建盒子固定装置,以使身体的位置在左上角(如果您使用的是b2PolygonShape::SetAsBox则意味着将中心b2PolygonShape::SetAsBox一半宽度和负高度的一半(因为Y轴反转)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM