将旋转角度转换为 Box2D 脉冲
如果之前已经回答过这个问题,我深表歉意,但我无法找到我想要的东西。
我有一个 Box2D 动态主体,我对其应用线性脉冲以将其变成射弹。因此,当我单击屏幕上的任意位置时,我希望身体投影到触摸位置。我还不关心力,只关心角度。
我已经让我的精灵旋转到指向触摸位置,这样我就可以检测到初始旋转角度,但是如何将这个角度(例如 45 度)转换为“b2Vec2”值,以便我可以精确地以 45 度发射主体?像这样的事情:
float rotationValue = 45.0f;
b2Vec2 vect = ??????
b2Vec2 PointVector = body->GetPosition();
body->ApplyLinearImpulse(vect, PointVector);
任何线索将不胜感激。
谢谢
Many apologies if this has been answered before but I wasn't able to quite find what I was looking for.
I have a Box2D dynamic body that I apply linear impulse to to turn it into a projectile. So when I click anywhere on the screen I want the body to be projected towards the touch location. I'm not concerned about the force yet, just the angle.
I already have my sprite rotating to point to the touch location so I can detect the initial rotation angle but how do I turn this angle, say 45 degrees into a "b2Vec2" value so that I can launch the body at exactly 45 degrees? something like this:
float rotationValue = 45.0f;
b2Vec2 vect = ??????
b2Vec2 PointVector = body->GetPosition();
body->ApplyLinearImpulse(vect, PointVector);
Any clues would be greatly appreciated.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
叹息 - 这就是为什么你应该在数学课上注意的原因:)
将角度转换为 vect 非常简单:
sigh - this is why you should pay attention in your Math class :)
Converting angles to vect is super simple: