如何创建基于旋转的脉冲矢量(Cocos2d、Chipmunk、Spacemanager)
所以我尝试用两个喷气背包创建角色 - 其中一个可以独立发射,以产生偏离重心的脉冲偏移(使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的角色的当前航向(它旋转的角度,逆时针方向)存储在
theta
中,并且您的脉冲向量位于ix
和中>iy
,则世界空间向量将为角度
theta
必须以弧度表示,cos
和sin
才能正常工作。如果您需要从度数转换为弧度,请将角度乘以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 inix
andiy
, then the world-space vector will beThe angle
theta
must be in radians forcos
andsin
to work correctly. If you need to convert from degrees to radians, multiply the angle byPI / 180.0
.If you want to see where this formula came from, read here.