On my endless struggle to create my first little game…
I would like to get collision strength detection working in my game. I found out that this can be done via getAppliedImpulse.
To test this I created a cube as a static object, and a ball as a rigid body falling on it. Some restitute in the materials and the ball is bouncing. Now I want to check how hard the cube was hit. So I give it a collision sensor “Ball Collide” and attach a python controller with the following content:
I did this “if not None” because I found out that every second collision is with a “None” object (???), always right after the “real” collision. (Leaving ball makes collision too?)
The output is always “0.0”. I also tried to move the last two lines in a separate script that’s connected to an always sensor - to see if I just didn’t get the right moment or so. Output: lots of “0.0”…
By now I really searched a lot on this, found nothing helpful…
I really need some help here. Any suggestions? Anyone used getAppliedImpulse successfully?
If the getAppliedImpulse function works at all I can only imagine that the figure returned would be of no use except maybe for the purpose of comparisons. Because in blender we can’t say that two colliding bodies are in contact for any particular time interval. So we can’t measure the changes in linear and angular momenta during the period that two real bodies would be in contact. We can’t integrate the force over time.
If you wanted an indicator, like a vertical bar that recorded the power of a collision, you could do it by calculating the loss of the kinetic energy (linear and rotational) of just the incoming object. Give it arbitrary units since you dont know ^t anyway. But to do that you’ve got to allow rigid body bullet physics for both objects.
So I’m not sure what you’re wanting to do. Maybe do some of your own physics on the second body? Maybe break a constrained object if hit sufficiently hard. If so it’s going to get very complex very quickly if you want them to behave like real objects . We’re not just talking about point objects with a single figure for elasticity. If you want to simulate it you’ll have to introduce arbitrary figures anyway. Better to fake it. Bit of trial and error with some randomness until it looks right.
Why can’t you tell if there’s contact? That’s what collision sensor does, as in the OP’s script. getAppliedImpulse doesn’t work and nor does getReactionForce, so I just use F=mdv/dt to get the force on, for example, a sphere. This information arrives therefore a timestep later than the collision but that doesn’t matter. It’s also not a substitute for getreactionforce in many situations.