i am using spacemanager and i want to calculate the force with which the objects collide so that i can adjust the开发者_如何学Go sounds and appropirate spirtes depending on the damage. can some one tell me how to calculate the forces. here is the code i got on this site.
if(!cpArbiterIsFirstContact(arb)) return;
cpFloat impulse = cpvlength(cpArbiterTotalImpulse(arb));
float volume = MIN(impulse/500.0f, 1.0f); NSLog(@"impulse is :%f",volume);
NSLog(@" impluse x:%f y:%f", cpArbiterTotalImpulse(arb).x , cpArbiterTotalImpulse(arb).y); if(volume > 0.05f){ [SimpleSound playSoundWithVolume:volume]; }
i have this in my POSTSOLVE method.i tried it in BEGIN aswell and all it prints is 0. i went through this site and found that i needs to do this. smgr.space->elasticIterations = smgr.space->iterations;
even after doing the above , sometimes i get 1 and some times it says "nan". is there something basic i need to know?
Thanks
From the documentation for cpArbiterTotalImpulse():
Returns the impulse that was applied this step to resolve the collision. These functions should only be called from a postSolve() callback, otherwise the result is undefined.
Note: If you are using the deprecated elastic iterations setting on your space, it will cause you to get incorrect results. Elastic iterations should no longer be needed, and you should be able to safely turn them off.
精彩评论