OK this is officially the most difficult Unity3D question on the site:
If you have two objects in Unity, perhaps drag A around with your finger, when you collide with B,
these days Unity sensibly gives you the forces PhysX has decided to apply to that item in the collision. Just use OnCollisionStay
...
Rigidbody rb;
void OnCollisionStay(Collision col)
{
if (rb.isKinematic) return;
if ( col.impulse.x != 0f || col.impulse.y != 0f )
Debug.Log(gameObject.name +" bashed, PhysX doing this .. "
+ col.impulse.x.ToString("f4") +" "
+ col.impulse.y.ToString("f4") +" "
+ col.impulse.z.ToString("f4") );
}
Looking at the doco http://docs.unity3d.com/ScriptReference/Collision.html
the worthwhile one is .impulse
impulse The total impulse applied to this contact pair to resolve the collision.
Great. But. Unfortunately it is utterly mysterious what coordinate system the impulse is being given in.
Try it and see. It's nuts. Is it relative to the direction between the two colliding objects (i.e. between transform
and col.transform
) or is it in some local space (which?) Is it perhaps relative to .relativeVelocity
vector?
What the hell is it? It is stoopid. Try and see.
I want the force applied simply in world space for goodness sake.
The documentation has no info and nobody is discussing it.