如何检测堆栈对象掉落
在我的游戏中,对象正在掉落,我必须抓住该对象并创建一个堆栈。我正在使用花栗鼠物理引擎来做到这一点。我能够创建堆栈,但我不明白如何检测堆栈是否像“Tower Bloxx”游戏一样掉落。
如果有人知道请帮帮我。
In my game, Objects are falling down and I have to catch that object and have to create a stack. I am doing this by using chipmunk physics engine. I am able to create stack but I don't understand how to detect that stack is falling like "Tower Bloxx" game.
If any one knows it please help me out.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要计算每个物体上的力和扭矩。
重力作用于物体的质心。如果这个物体悬垂在另一个物体上,那么可能会产生扭矩,使物体滚落。
如果您已经了解了物理原理,使其更加真实,那么您可以通过监视每个对象的速度方向来检测堆栈是否稳定。如果它正在改变符号,并且幅度越来越小,那么它就会趋于稳定。 (如果它为零,则已经稳定。)
You need to calculate the forces and torques on each object.
Gravity acts on the center of mass of an object. If this object overhangs another object, then there could be a torque that could roll the object off.
If you've got the physics down so that it's realistic, then you can detect whether the stack is stable or not by monitoring the direction of the velocity for each object. If it's changing sign, and the magnitude is getting smaller, then it's stabilizing. (If it's zero, it is stable already.)
我不熟悉花栗鼠引擎的结构,但是它有某种碰撞事件吗?如果是这样,您可以使用该事件来检测除基础块之外的任何块何时击中地面物体并结束游戏。
I'm not familiar with the structure of the chipmunk engine, but does it have some sort of collision event? If so, you could use that event to detect when any block but the base one hits the ground object and end the game then.