如何创建基于旋转的脉冲矢量(Cocos2d、Chipmunk、Spacemanager)

发布于 2024-10-20 08:12:23 字数 376 浏览 7 评论 0原文

所以我尝试用两个喷气背包创建角色 - 其中一个可以独立发射,以产生偏离重心的脉冲偏移(使用 Cocos2d、Chipmunk 和 SpaceManager)。

我的问题是,默认情况下,脉冲函数不考虑对象的当前旋转(即其指向的方向),因此无论方向是什么,我使用的脉冲偏移和方向最终都是相同的角色指向内。

我试图创建一个更真实的模型 - 其中脉冲基于对象的现有旋转。我确信我可以以编程方式维护一个向量变量,该变量保存角色指向的当前方向并使用它,但必须有一个更简单的答案。

我听说人们写了关于世界空间与身体相对坐标的文章,以及默认情况下世界空间的冲动如何,而身体相对坐标将解决我的问题。这是真的吗?如果是这样,如何在这两个坐标系之间进行转换?

如果您能给我任何帮助,我将不胜感激。

So im trying to create character with two jetpacks - either of which can be fired independently of one another to create an impulse offset from the center of gravity (Using Cocos2d, Chipmunk, and SpaceManager).

My problem is that the by default, the impulse function doesn't take into account the current rotation of the object (i.e. which way its pointing), therefor the impulse offset and direction that I use ends up being the same no matter what direction the character is pointing in.

Im trying to create a more realistic model - where the impulse is based on the existing rotation of the object. Im sure I could programmatically just maintain a vector variable that holds the current direction the character is pointing and use that, but there has to be a simpler answer.

Iv heard people write about world space vs body relative coordinates and how impulse is world space by default, and body relative would fix my problem. Is this true? If so how do you convert between these two coordinate systems?

Any help you could give me would be Greatly appreciated.

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

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

发布评论

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

评论(1

奈何桥上唱咆哮 2024-10-27 08:12:23

如果您的角色的当前航向(它旋转的角度,逆时针方向)存储在 theta 中,并且您的脉冲向量位于 ix中>iy,则世界空间向量将为

ix_world = ix * cos(theta) - iy * sin(theta);
iy_world = ix * sin(theta) + iy * cos(theta);

角度 theta 必须以弧度表示,cossin 才能正常工作。如果您需要从度数转换为弧度,请将角度乘以 PI / 180.0

如果您想了解此公式的来源,请阅读此处

If you have the current heading of your character (the angle it has rotated through, going counter-clockwise) stored in theta, and your impulse vector is in ix and iy, then the world-space vector will be

ix_world = ix * cos(theta) - iy * sin(theta);
iy_world = ix * sin(theta) + iy * cos(theta);

The angle theta must be in radians for cos and sin to work correctly. If you need to convert from degrees to radians, multiply the angle by PI / 180.0.

If you want to see where this formula came from, read here.

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