- Home /
Collision impact force
Hi,
I want to know how to get the impact force between 2 objects. There's a algorithm or a method that do it for me?
I know that the force is mass * velocity, but how can I know the velocity at a direction?
Thanks! Borgo.
EDIT: I'm making a 2D game, so, I will use only the x and y axis. If I do something like this is correct?:
 impact = (a.velocity.x - b.velocity.x);
 impact += (a.velocity.y - b.velocity.y);
 impact *= a.mass*b.mass;
 
 when 
 a = objecta.rigidbody 
 and
 b= objectb.rigidbody
Thanks again.
For a good rundown on the principles behind elastic/inelastic collisions and the forces involved, check out the Wikipedia article here.
Answer by Borgo · Jul 09, 2011 at 12:31 AM
I have done!! I will share:
Edit: code corrections;
 var impactVelocityX = rigidbody.velocity.x - contact.otherCollider.rigidbody.velocity.x;
 impactVelocityX *= Mathf.Sign(impactVelocityX);
 var impactVelocityY = rigidbody.velocity.y - contact.otherCollider.rigidbody.velocity.y;
 impactVelocityY *= Mathf.Sign(impactVelocityY);
 var impactVelocity = impactVelocityX + impactVelocityY;
 var impactForce = impactVelocity * rigidbody.mass * contact.otherCollider.rigidbody.mass;
 impactForce *= Mathf.Sign(impactForce);
Thanks!
I think using a Vector2 here (or Vector3 if you wanted to make it a general function for reuse) would work nicely. You could store each difference of velocity as the component (`iV.x` and iV.y, for example) and then use the existing vector functions available such as $$anonymous$$agnitude, etc and still maintain the directional info if you need it (by virtue of being a Vector).
Thanks, just got carried away with the code and forgot to use the Vector2 :)
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                