花栗鼠物理学:速度问题
我正在制作一款 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本上,在与墙壁的完美弹性碰撞(没有能量损失)中,我猜这就是您想要的,与墙壁垂直(垂直)的速度分量被反转(反转)。切向分量保持不变。例如,如果墙沿 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.