Box2d抗风能力

发布于 2024-11-29 08:30:13 字数 81 浏览 1 评论 0 原文

我想制作一个带有风车的游戏,并希望通过 b2vec2 重力矢量产生风。我找不到关于风阻的明确解释。用box2d可以吗?请您给我指出必要的功能和文档。

I'd like to make game with some windmill in it and want to make wind via b2vec2 gravity vector. I can't find some clear explanation about wind resistance. Is it possible with box2d? May I ask you to point me to necessary functions and documentation please.

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

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

发布评论

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

评论(2

攒一口袋星星 2024-12-06 08:30:13

您尝试做的事情对于 box2d 来说很可能是不可能的,因为这将涉及在 3d 中模拟物理,而 box2d 仅执行 2d 物理。如果我是你,我就会伪造动画。将风车的叶片放在与风车主体不同的 CCSprite 中,然后使用与风速匹配的 CCAnimation 绕 z 轴旋转叶片。

What you are trying to do is most likely impossible with box2d, as that would involve the physics being simulated in 3d, while box2d only does 2d physics. If I was you, I would just fake the animation. By having the blades of the windmill in a separate CCSprite than the body of the windmill and then rotating the blades around the z-axis using a CCAnimation that matches the wind speed.

待天淡蓝洁白时 2024-12-06 08:30:13

对于游戏

根据游戏的不同,您可能不需要担心阻力(风阻)。您可能可以使用ApplyForce或扰乱重力(就像您在问题中提到的那样)将物体朝风吹的方向推动。

如果你真的想模拟风阻

看起来线性阻尼可能会有所帮助,尽管不现实。真正的空气阻力不是线性的。

您还可以在每帧执行与速度相反的ApplyForce。不幸的是,自从我上力学课以来已经有一段时间了,所以我无法帮助您编写代码,但您可以查看这篇维基百科文章的公式

我从这个线程中窃取了大部分信息:

http://www.box2d.org/forum/viewtopic.php?f =3&t=2718

如果您仍然遇到问题

我在回答中做了一些假设。我假设您正在对风和空气阻力等事物进行基本近似。我还假设您并没有真正尝试对推动风扇的气体进行建模,因为在 2D 中您可能不会有太多运气,即使您尝试过,我也无法想象它会给您的游戏带来多少好处。

如果您仍然感到困惑,请尝试在您的问题中添加一些示例代码,或者更详细地描述您要尝试模拟的内容。

For games

Depending on the game, you may not need to worry about drag force (wind resistance). You could probably get away with pushing objects in the direction the wind is blowing, using an ApplyForce or messing with gravity (like you mentioned in the question).

If you really want to model wind resistance

Looks like linearDampening could be helpful, though unrealistic. True air resistance isn't linear.

You could also do an ApplyForce every frame, opposite the velocity. Unfortunately its been a while since I've taken my mechanics class, so I can't help you with the code, but you could look at this wikipedia article for the formulas

I stole most of this info from this thread:

http://www.box2d.org/forum/viewtopic.php?f=3&t=2718

If you are still having problems

I made some assumptions in my answer. I assumed that you're making rudimentary approximations of things like wind and air resistance. I also assumed you're not truly trying to model a gas pushing a fan, as you probably won't have much luck doing that in 2D, and even if you tried, I can't imagine it adding much to your game.

If you're still confused, try adding some example code to your question, or describe what you are trying to simulate in more detail.

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