如何将 box2d 主体指向运动方向?

发布于 2024-12-04 13:34:20 字数 166 浏览 6 评论 0原文

大家好,正如标题所示,我想将 box2d 主体移动到运动方向。任何人都可以提供一些线索,我如何实现这一目标?谢谢

,我现在使用的

b->SetLinearImpusle(force,direciton);

身体只是根据碰撞而旋转

Hi guys as the title suggest i want to move a box2d body the direction of motion .. can anyone give some clue how can i achieve this ? Thanks

right now i am using

b->SetLinearImpusle(force,direciton);

the body just rotates according to the collision

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

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

发布评论

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

评论(1

三五鸿雁 2024-12-11 13:34:20

如果您只想在指定方向应用脉冲:

b2Vec2 direction(1, 0);
direction.Normalize();
float force = 10.0f;
b->ApplyLinearImpulse(force*direction, b->GetPosition());

ApplyLinearImpulse 的第二个参数是应用脉冲的点

If you want just to apply an impulse in specified direction:

b2Vec2 direction(1, 0);
direction.Normalize();
float force = 10.0f;
b->ApplyLinearImpulse(force*direction, b->GetPosition());

the second parameter of ApplyLinearImpulse is the point where to apply the impulse

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