• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by canahari · Dec 31, 2011 at 09:39 PM · colliderforce

what force did collider collide with?

I have a collider and it sometimes collides with another colliders. I would like to know the force the other collider chrashed with mine (to calculate damage). I'm not interested in torque and friction and anyt$$anonymous$$ng separately, only the resultant force w$$anonymous$$ch my collider gets. I hope I was clear enough. Is there any way to know t$$anonymous$$s?

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fattie · Mar 28, 2016 at 08:04 PM 0
Share
avatar image meat5000 ♦ · Mar 28, 2016 at 08:12 PM 0
Share
avatar image Fattie meat5000 ♦ · Mar 28, 2016 at 08:15 PM 1
Share

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by suyujin · Jan 01, 2012 at 12:10 AM

To my understanding you can't actually access collision force, per se. You'll probably want to look at collision normals, the velocity, and object masses. I'm sure you can find an equation pretty quickly. There was a pretty long forum discussion on the matter here: http://forum.unity3d.com/threads/23746-getting-impact-FORCE-not-just-velocity Might help you out a bit! Good luck!

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fattie · Mar 28, 2016 at 08:05 PM 0
Share
avatar image
0

Answer by aldonaletto · Jan 01, 2012 at 02:09 AM

You can't know the reaction force directly, but it can be calculated: you can get the rigidbody.velocity variation due to the collision, calculate the acceleration and multiply by the rigidbody.mass to get the force. Unfortunately, the velocity changes in the first FixedUpdate after the collision. A good way to work around t$$anonymous$$s is to create a fake OnCollisionEnter - let's call it OnAfterCollision - and call it in the first FixedUpdate after the collision:

 private var fCollided: boolean = false;
 private var fLastVel: Vector3;
 private var fCollision: Collision;
 
 function OnCollisionEnter(coll: Collision){
   fCollision = coll; // save collision data
   fCollided = true; // signal that a collision happened
 }
 
 function FixedUpdate(){
   if (fCollided){ // if collision happened...
     fCollided = false; // reset flag
     // calculate acceleration due to collision
     var acc = (rigidbody.velocity - fLastVel)/Time.fixedDeltaTime;
     // convert to force:
     var force = rigidbody.mass * acc;
     // call OnAfterCollision passing the Collision 
     // info and the reaction force:
     OnAfterCollision(fCollision, force);
   }
   fLastVel = rigidbody.velocity; // update last velocity
 }
 
 // place your damage code in OnAfterCollision: you will have all the
 // original Collision data and the reaction force:
 
 function OnAfterCollision(coll: Collision, force: Vector3){
   print("Force="+force.magnitude);
 }

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Stephane Wantiez · Jul 31, 2014 at 12:32 PM 1
Share
avatar image
2

Answer by Peter G · Jan 01, 2012 at 04:23 AM

I'm not sure how you would isolate force strictly from collision information, but you could calculate the impulse on the object relatively easily.

 Impulse = m∆v

Assuming we have an inelastic collision.

  m1v1 + m2v2 = (m1 + m2)vf
  vf (velocity final) = (v1m1 + v2m2) / (m1 + m2)

  then....

  ∆v = vf - v1

  so the impulse = m∆v

Now, collision information provides a relative velocity. If you set the velocity of the second object to the relative velocity and then treat the velocity of your current object as zero, you can simplify the math.

   v1 = 0.0
   v2 = collision.relativeVelocity

   vf = v2m2 / (m1 + m2)
   ∆v = vf

In code terms:

 function OnCollisionEnter (col : Collision) {
       var vFinal = col.rigidbody.mass * col.relativeVelocity / (rigidbody.mass + col.rigidbody.mass);
       var impulse = vFinal * rigidbody.mass;
 }

Now, elastic collisions. If there is no energy loss (bounciness >= 1) then the ∆v is the velocity of the 2nd object minus the velocity of the first object:

 var impulse = rigidbody.mass * ( col.rigidbody.velocity - rigid.body.velocity);
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by TheGameLearner · Jun 04, 2018 at 05:18 AM

use collision.impulse you can get Vector3 value of force.

 OnCollisionEnter(Collision col)
 {
      Vector3 impactForce = col.impulse / Time.deltaTime;
      //Handle ahead yourself!! Cheers
 
 }

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image bartvandalen · Mar 18, 2022 at 10:41 AM 0
Share

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Hitting Collider,Not Being Effected ? 1 Answer

How to Move Player in Particular Direction Without holding Down a Button? 0 Answers

Adding force to a bullet as it hits object? 2 Answers

collider not moving with the object 1 Answer

pulling objects 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges