• 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
0
Question by agentsmith · Jul 29, 2010 at 12:58 AM · physicsforce

How do I calculate the force affecting a rigidbody?

Hi all,

I have an explosion force (Rigidbody.AddExplosionForce) that is affecting other rigid bodies (npcs, crates, tea cup, rubber ducky, etc) and I would like to detect how much force is being applied during collision with the explosive force. In the manual it says the explosive force function drops of linearly over distance to rigidbody; I read another post here to try and determine the acceleration (change in velocity) and then you use the F=ma but getting the acceleration from the change in velocity seems a little "clunky." I thought maybe there would be something in "Collision" information that would say here's the force vector or even a magnitude.

Thanks in advance, you guys rock!

Comment
Add comment · Show 2
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 qJake · Jul 29, 2010 at 03:11 AM 0
Share

I'm confused, what do you want, exactly? What is the end result you're looking for?

avatar image agentsmith · Jul 29, 2010 at 04:28 AM 0
Share

I'd like to know the force impacting the rigidbody. The end result would be the ability to do something depending on how much force is applied. Eg. If force.magnitude > 50 newtons then do something cool.

2 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Magnus Wolffelt · Jul 29, 2010 at 10:24 AM

There's probably no neat way to get the force applied. It would be nice if the function did actually return the result of its calculation, or if it used another publicly available counterpart for the calculation only.

Anyway, I think you're best off implementing your own function for this. It's not very complex, and you can make it more complex/interesting if you want by looking at the colliders and see how much they "face" the explosion, which should determine how much the body is affected.

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 agentsmith · Jul 30, 2010 at 05:48 AM 0
Share

Ok I will do that; I wanted to make sure I wasn't missing anything as I trolled the API and couldn't find anything. Thank you for responding, I appreciate it!

avatar image
0

Answer by jfabris · Oct 08, 2011 at 08:19 PM

This is what I came up with. A little clumsy but it works. The one thing I don't understand is, if explosionRadius=5, why does the explosion affect objects up to 30 units away???

var explosionRadius : float = 5.0; //The radius of our collision. var explosionPower : float = 350.0; //The amount of power the explosion shall have. 350

 var colliders : Collider[] = Physics.OverlapSphere (transform.position, explosionRadius); //Sets a collider sphere variable.
 
 //For each new thing the hit var, that we define in the function, that the explosionRadius collides with.
 for (var hit in colliders)
  {     
     //If the thing we hit is a rigidbody.
     if (hit.rigidbody)  
     {
         
         if(hit.rigidbody.name=="EnemyTank1")
         {
             var d=Vector3.Distance(transform.position,hit.rigidbody.position);
             var radius=30;
             var f=explosionPower*(radius-d)/radius;
             if(d>radius) f=0;
             
             print("hit enemy tank, power="+f+" distance="+d+" pow="+(Mathf.Pow(f,2)/100000));
             
             if(ps)
             {
                  ps.AddScore(10);
             }
             else
             {
                 print("ps is null");
             }                
             
         }
         
         hit.rigidbody.AddExplosionForce(explosionPower, transform.position, explosionRadius); //Add an explosion force that affects all rigidbody's.
     } 
 }
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

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

1 Person is following this question.

avatar image

Related Questions

Bend object with physics interaction 0 Answers

Predicting land position with drag applied 0 Answers

What is the best way to apply force, then come to a smooth stop on control release? 1 Answer

Calculating required force for pushing a body to a desired position at once 0 Answers

increasing knockback of a rigidbody as received damage increases (like super smash) 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