iPhone 上的 Box2D 浮力
我想知道是否有人可以指导我如何在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
浮力等于流体密度乘以排开流体的体积(这给出了排出的流体的质量乘以重力加速度。然而,计算排出的液体量的成本可能很高。我建议根据物体的大小以及它浸没在液体中的深度对位移的体积进行简单的估计。
流体中另一个非常重要的力是阻力 力量。这使得在粘稠流体中高速移动物体变得更加困难。只需将速度阻尼某个常数值即可轻松估计阻力:
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
whereb
is your damping value andv
is the object's velocity.