- Home /
How to get inverse Force?
I have 2 game object are collisions. I use void OnCollisionEnter(Collision other ) and i want to get inverse Force. Can i do it? Please help me.
Answer by Tsumik1 · Jan 07, 2013 at 10:32 AM
If you have attached rigid bodies to each object that collides there should be some forces acting by default.
For a little more control use the AddForce method in the RigidBody component. http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.AddForce.html
Answer by Kryptos · Jan 07, 2013 at 10:20 AM
You can get a pretty good hint of the collision force by using other.relativeVelocity.
You can try to apply the reverse force by adding a force back to the rigidbody:
rigidbody.AddForce( -other.relativeVelocity, ForceMode.VelocityChange ); // Note: I did not check the sign. I guess it needs to be negated but I'm not sure.
But this may not be exactly the reverse force, since the PhysicMaterial can change things a bit. Also the direction of the relative velocity is along the segment of the two objects centers which might not fit all cases.