检查花栗鼠物理中的碰撞速度

发布于 2024-09-07 18:02:15 字数 190 浏览 3 评论 0 原文

我正在使用 iPhone 版 Chipmunk 5 和 Cocos2D。在两个特定对象之间发生碰撞时,我想运行一个方法来检查碰撞的速度,如果超过 x,则运行一组代码,如果低于 x,则运行另一组代码。

现在,我了解了基础知识,但我无法编写运行碰撞检测方法的代码以及检查冲击速度的代码。

任何帮助或指示将不胜感激。

干杯。

I'm using Chipmunk 5 for iPhone, with Cocos2D. Upon collision between two specific objects I'd like to run a method which checks the velocity of that collision, if it's over x it runs one set of code, if it's under x it runs another.

Now, I understand the basics but I can't work out the code to run a method on collision detection, and the code to check impact speed.

Any help or pointers would be greatly appreciated.

Cheers.

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

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

发布评论

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

评论(2

So要识趣 2024-09-14 18:02:15

查看 addCollisionCallbackBetweenType 函数rel="nofollow noreferrer">SpaceManager.h 这可能有助于注册碰撞。

之后,您可以检查 cpBody 对象的 v 属性,即速度的 cpVect。 (http://code.google .com/p/chipmunk-physicals/source/browse/trunk/include/chipmunk/cpBody.h,未链接,新用户。)

我对花栗鼠没有经验,但这就是谷歌搜索的结果。

Check out the addCollisionCallbackBetweenType function in SpaceManager.h That might help with registering collisions.

After that, you can check the v property for the cpBody objects, a cpVect of the velocity. (http://code.google.com/p/chipmunk-physics/source/browse/trunk/include/chipmunk/cpBody.h, not linked, new user.)

I am not experienced with chipmunk, but that's what a little googling turned up.

猫瑾少女 2024-09-14 18:02:15

对于 Chipmunk 5,假设您想要播放声音或应用碰撞造成的伤害,我建议从求解后回调中调用 cpArbiterTotalImpulse() 函数。您可以在此处的文档中找到更多信息。
http://chipmunk-physicals.net/ release/Chipmunk-5.x/Chipmunk-5.3.5-Docs/#Callbacks

另外,Chipmunk 5 目前已经相当老了。如果不麻烦的话,我建议升级到6.x。然后您可以使用 cpArbiterTotalKE() 函数。 (不过,如果现有项目已接近尾声,我会坚持使用 5.x。)动能比脉冲强度更好地指示碰撞有多“糟糕”。

For Chipmunk 5, assuming that you want to play a sound or apply damage from the collision, I'd recommend calling the cpArbiterTotalImpulse() function from a post-solve callback. You can find more information in the docs here.
http://chipmunk-physics.net/release/Chipmunk-5.x/Chipmunk-5.3.5-Docs/#Callbacks

Also, Chipmunk 5 is fairly old at this point. If it's not a hassle, I'd suggest upgrading to 6.x. Then you could use the cpArbiterTotalKE() function. (If you are near the end of an existing project though, I'd just stick with 5.x.) The kinetic energy is an even better indicator of how "bad" a collision is than the impulse strength.

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