开发者

Check collision speed in Chipmunk Physics

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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜