花栗鼠物理学:速度问题

发布于 2024-09-03 12:05:24 字数 310 浏览 1 评论 0原文

我正在制作一款 iPhone 游戏,其中的主角是一个根据设备加速计旋转而滚动的球。

我还没有开始这部分的编码,但我想知道你们是否有一个很好的方法来解决这个问题:

我尝试稍微研究一下花栗鼠,我注意到物体具有属性 v,这是一个点包含 x 和 y 速度。

我认为这样做是一个坏主意:

playerBody->v = ccp(accelerometer.x * 5, playerBody->v.y);

因为它只会卷起墙壁和其他东西,

有没有更好的解决方案来做到这一点?

I'm making an iPhone game where the main actor is a ball that rolls depending on the device's accelerometer rotation.

I haven't started on this part of the coding yet, but I was wondering if you guys had a nice way of solving this:

I tried looking a little into chipmunk, and I noticed that bodies have the property v, which is a point containing x and y velocities.

I was thinking it'd be a bad idea to just do like:

playerBody->v = ccp(accelerometer.x * 5, playerBody->v.y);

because it'd just roll up of walls and stuff,

is there a better solution to do this?

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

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

发布评论

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

评论(1

混吃等死 2024-09-10 12:05:24

基本上,在与墙壁的完美弹性碰撞(没有能量损失)中,我猜这就是您想要的,与墙壁垂直(垂直)的速度分量被反转(反转)。切向分量保持不变。例如,如果墙沿 x 轴,则 v_y = -v_y。我没有使用过 Chipmunk,所以我不会尝试告诉您执行此操作的实际语法。

Basically, in a perfectly elastic collision (no energy lost) with a wall, which I'm guessing is what you want, the component of the velocity that is normal (perpendicular) to the wall is reversed (inverted). The tangential components stay the same. For instance, if the wall is along the x-axis, then v_y = -v_y. I haven't used Chipmunk so I won't attempt to tell you the actual syntax for doing this.

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