# Tutorial :Check collision speed in Chipmunk Physics

### Question:

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.

### Solution:1

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.

### Solution:2

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.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »