Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
1
Question by Rhithik · Jul 12, 2012 at 04:49 AM · rigidbodyforceexplosioncalculate

How to calculate force from explosion on a rigidbody

Lets say I have a ball the explodes on contact with anything using the Rigidbody.AddExplosion function. It explodes it front of 10 cubes which are in a line and whom are rigid bodies. How would I go about calculate how hard each rigid body was hit with the explosion? The closer the cube is to the explosion, the harder it should be hit. I've been searching for this answer for the past couple days and cannot find it or even come up with one. Any help is appreciated. Thanks.

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 thaiscorpion · Jul 12, 2012 at 10:19 AM 0
Share

Rhithik not quite sure what you want, do you want to know the exact force? or do you want to apply less force the higher the distance? $$anonymous$$aybe show us some code you have to understand better what you are trying to do.

avatar image Yoerick · Jul 12, 2012 at 01:40 PM 0
Share

I don't really believe you've been looking for this for days.

The first thing I found on google is the Rigidbody.AddExplosionForce in the Unity Script Reference and this page is as clear as it can get. It even says that "The explosion force will fall off linearly with distance to the rigidbody.". It's all in the function, just give it a certain force and a range and it calculates the distance falloff for you. I don't really get what you want more?

Second hit on google: http://unity3d.com/support/resources/unity-extensions/explosion-framework

It's really all in there, download it and give it a look, it does exactly what you describe.

1 Reply

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

Answer by Bunny83 · Jul 12, 2012 at 03:33 PM

Rigidbody.AddExplosionForce already do the calculation for you. You just have to specify the center of the explosion and call that function on the RB.

The explosion framework, which has been mentioned by Yoerick above, does probably use this function and is a good example how to use it.

Generally You just need to find all objects that are in "range" and call AddExplosionForce on all of them with exact the same parameters:

 // C#
 float range = 10.0f;
 float force = 100.0f;
 
 Collider[] objs = Physics.OverlapSphere(transform.position, range);
 foreach(Collider C in objs)
 {
     var R = C.rigidbody;
     if (R == null)
         continue;
     R.AddExplosionForce(force, transform.position, range);
 }

edit
Since your question isn't very detailed what you actually want, most people wait for a clarification what you want to do and for what purpose.

If you need to know some kind of damaging value for each object, well You can't see how AddExplosionForce calculates the distance. It could be linear, it could be quadratic or logarithmic. If you really want to know how it calculates the force, you might do some tests to figure it out.

The other possibility is that you just calculate a damage-value yourself, the way you want.

You usually start by determine the distance of each object to the explosion source and linearize the distance within the range:

 // C#
 float CalculateExplosionValue(Vector3 aSource, Vector3 aTarget, float aRange)
 {
     float dist = (aTarget - aSource).magnitude;
     if (dist > aRange)
         return 0.0f;
     return 1.0f - dist / aRange; 
 }

This function will return 1.0f if the object "sits" on the explosion and 0.0 when it's at max range or further away. Any position within the radius will be linearly between 1.0 and 0.0.

This can now be made a quadratic falloff or any other function graph you like.

Comment
Add comment · Show 3 · 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 fafase · Jul 12, 2012 at 04:25 PM 0
Share

Note that the equation is probably

 I= Power/4*Pi*r^2  
avatar image Rhithik · Jul 12, 2012 at 05:25 PM 0
Share

Yes thank you Bunny83 that is what I was looking for.

avatar image Bunny83 · Jul 12, 2012 at 10:52 PM 0
Share

@fafase: Could be, but i guess it would be

 F = Power*3 / 4*Pi*r^3 

;) The pressure reduces linearly with the expanding volume. But in the end it's quite irrelevant since it's just a simulation.

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.

Follow this Question

Answers Answers and Comments

9 People are following this question.

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

Related Questions

Calculate Position of Rigidbody after applying Force 0 Answers

Decrease ExplosionForce and damage continously by distance 2 Answers

Exploide GameObjects Into BrokenParts : Unity 1 Answer

AddExplosionForce 0 Answers

calculate the estimated distance travel based on the Force applied to Rigid Body 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