将我的身体移动到一个点

发布于 2024-09-09 04:58:05 字数 42 浏览 6 评论 0 原文

我正在使用 2d 框。我只是想把我的身体移动到重点。最好的方法是什么?

I am using box 2d. I just want to move my body to the point. What is the best way to do this?

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

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

发布评论

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

评论(1

旧情别恋 2024-09-16 04:58:05

当你说你只是想要移动身体时,你的意思是你想要施加一个力来让身体到达一个点吗?

有一个专为鼠标移动而设计的关节,如果您想在 iPhone 上拖动主体,它可能会很适合您的情况。它称为“鼠标关节”,在 这些 box2d 文档 上位于 8.10 之下。

如果您想要一个不响应撞击物体的物体,而是根据它所在的位置和要去的方向推动物体,请选择 相同的文档

希望有帮助。你的问题很模糊。

编辑回应评论:

嗯,一般来说,执行此操作的方法是 cpBodyApplyForcecpBodyApplyImpulse。有很多方法可以使用它来将身体移动到某个位置,并且它们可能会变得比我在评论中总结的更复杂。从本质上讲,您正在接触的内容可以通过游戏人工智能编程源更好地涵盖。

最基本的方法是施加一个力,该力是从物体到目标位置的距离的某个倍数(在每个轴上)。如果您希望物体慢慢停止,搜索词“AI到达行为”可能是个好主意。我在 gamedev.net 上找到了此讨论

When you say you just want to move the body, do you mean you want to apply a force to get the body to a point?

There's a joint designed for mouse movement, and it might work well in your case if you want to drag bodies around on an iPhone. It's called the Mouse Joint, and it's under 8.10 on these box2d docs.

If you want a body that doesn't respond to things hitting it, but pushes things around based on where it is and where it is going, go for the b2_kinematicBody on the same docs

Hope it helps. Your question is very vague.

EDIT in response to comment:

Well, generically the way to do this would be cpBodyApplyForce or cpBodyApplyImpulse. There are many ways to use this to move the body to a position, and they can get more complex than I can summarize in a comment. Essentially, you're getting into stuff that can be better covered by game AI programming sources.

The most basic way would be to apply a force that is some multiple (on each axis) of the distance from the object to the target position. If you want the object to slowly stop, the search terms "AI arrive behavior" might be a good idea. I found this discussion on gamedev.net.

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