iPhone 上的 Box2D 浮力

发布于 2024-11-02 09:07:45 字数 429 浏览 3 评论 0原文

我想知道是否有人可以指导我如何在 iPhone 上使用 Box2D 实现以下目标:

1)我有一个正常重力为 -9.8 的 Box2D 世界 2) 屏幕的下半部分是水体

所以当我的精灵碰到水体时,我希望他能做出浮力反应(类似于此视频中发生的情况:http://www.youtube.com/watch?v=0uX-1GXYIss)

是实现此目标的最佳方法1

) 只需计算主角精灵的 y 位置,然后相应地切换重力变量

,或者 2) Box2D 中是否内置了特定功能,允许我将“水”精灵设置为在我的世界中表现得像水一样,并且“推”我的主角精灵向上(同时仍然尊重 9.8 的世界重力)

任何信息将不胜感激

I was wondering if anyone can give me pointers on how to achieve the following using Box2D on the iphone:

1) I have a Box2D world with normal gravity of -9.8
2) The bottom half of the screen is a body of water

So when my sprite hits the body of water, I want him to react with buoyancy (similar to what's going on in this video: http://www.youtube.com/watch?v=0uX-1GXYIss)

Is the best way to achieve this to

1) simply calculate the y position of the main character sprite and then switch the gravity variable accordingly

or 2) is there a specific feature built into Box2D that will allow me to set my "water" sprite to behave as water in my world and "push" my main character sprite up (while still respecting the world gravity of 9.8)

Any info would be appreciated

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

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

发布评论

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

评论(1

情绪 2024-11-09 09:07:45

浮力等于流体密度乘以排开流体的体积(这给出了排出的流体的质量乘以重力加速度。然而,计算排出的液体量的成本可能很高。我建议根据物体的大小以及它浸没在液体中的深度对位移的体积进行简单的估计。

流体中另一个非常重要的力是阻力 力量。这使得在粘稠流体中高速移动物体变得更加困难。只需将速度阻尼某个常数值即可轻松估计阻力:Force_drag = -b * v,其中 b 是阻尼值,v code> 是物体的速度。

The buoyant force is equal to the density of the fluid times the volume of the fluid displaced (which gives you the mass of the fluid displaced) times the acceleration due to gravity. The volume of fluid displaced can be costly to compute however. I would suggest making a simple estimate of the volume displaced based on the size of the object and how far it is submerged in the liquid.

Another very important force in fluid is the drag force. This is what makes it more difficult to move objects at high velocity through thick fluids. The drag force can easily be estimated by simply damping the velocity by some constant value: Force_drag = -b * v where b is your damping value and v is the object's velocity.

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