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
0
Question by Mattias-Wargren · Jan 26, 2011 at 10:45 PM · physicsrigidbodyexplosion

How do I make an explosion affect my gameobjects?

I have some Cubes (with rigidbodies) in my scene that I want to blow up. How do I get them to react/get affected by for example a bomb thrown in front of them? I found the following code that works nice, but I would like the cubes to be thrown up in the air as well.

var explosionTime = 1.0; var explosionRadius = 3.0; var explosionPower = 500.0;

function executeCollision() { var colliders : Collider[] = Physics.OverlapSphere( transform.position, explosionRadius );

 for( var hit in colliders )
 {
     if( hit.rigidbody )
         hit.rigidbody.AddExplosionForce( explosionPower, transform.position, explosionRadius );
 }

}

Comment
Add comment
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

5 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by jjxtra · May 11, 2015 at 06:11 AM

  Collider[] objects = UnityEngine.Physics.OverlapSphere(explosionCenterPosition, explosionRadius);
  foreach (Collider h in objects)
  {
     Rigidbody r = h.GetComponent<Rigidbody>();
     if (r != null)
     {
         r.AddExplosionForce(explosionForce, explosionCenterPosition, explosionRadius);
     }
 }
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
1

Answer by mrde · Jan 26, 2011 at 11:13 PM

add this code to your cub (with rigidbody) and it will give them velocity to up every mouse left click. not tested

void Update()
{
if (Input.GetButtonDown("Fire1")) {
rigidbody.velocity = transform.TransformDirection(new Vector3(0, 0, 5f));
}

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
1

Answer by Jessy · Jan 26, 2011 at 11:14 PM

http://unity3d.com/support/documentation/ScriptReference/Rigidbody.AddExplosionForce.html

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 BloodOmen · Feb 26, 2014 at 06:33 AM 0
Share

This is the right answer. AddExplosionForce have a upward modifier that is 0.0f by default.

avatar image
0

Answer by jtok4j · Apr 22, 2019 at 03:25 AM

My Two Cents:

For AddExplosionForce to work, the object you want to have flying around, must have:

  1. a rigidbody AND (Mandatory)

  2. a collider... simple, yet took me 30 minutes to figure out... Keep on Creating!

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 thomasfriday · Jul 12, 2021 at 06:05 PM

Here's a short Youtube video that covers exactly how to explode a cube: https://youtu.be/wcQqYOSteSs


exploding cube

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

CharacterController and RigidBody 1 Answer

Move rigid body using explosion force in C# 0 Answers

Earth quake with physics? 1 Answer

Rigidbody.AddExplosionForce() Not Playing Nice With Trigger Colliders 1 Answer

Touch input to move rigidbody using explosion force in C# 0 Answers


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