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 adamchakov · Feb 25, 2014 at 12:26 AM · triggerdestroyexplosionbox

Explosion triggers another explosion

hey guys , i think this concept have never been mentioned ,so what i want to achieve is :

°there's box (1)

°and there's Box(2) near box(1)

--is it possible to ( when box(1) explodes , the explosions will affect box(2) and make it explode too )

is this possible ? thanks !

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 instruct9r · Feb 25, 2014 at 12:31 AM 0
Share

What do you mean by explode? The box dissapears and some particles shows up? You can make yield, you can make a trigger, that animated inflation (Scale) with certain speed, so when it reaches the other box it activates it. There are lot's of possible ways to achieve that.

avatar image adamchakov · Feb 25, 2014 at 12:41 AM 0
Share

hey @instruct9r thanks for the reply ,yeah exactly in my case , the box gets destroyed and some particles show up , yeah i taught about triggers , can we use particles ? like if particles touches Box(2) , box(2) will get destroyed ?

avatar image Kindaiman · Dec 02, 2017 at 02:20 PM 0
Share

Hi Adamchakov, I have being trying to achieve it but with no success. Can You please help me if you can. I have stoped building my game because of this situation. I want to explode a box and it triggers other explosions near by. thanks

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by MisterMike · Feb 25, 2014 at 01:10 AM

If you're talking about causing a chain-reaction one way to do it would be to do a Physics.SphereCastAll against a layer holding all explosive objects once an object detonates to see if any are in range to be affected.

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 nesis · Feb 25, 2014 at 02:54 AM 0
Share

This answer is what I did to make something like what the question is asking about - a chain of explosions like what you get with bomb flowers in Legend of Zelda: Ocarina of Time.

For a little more detail, you'd make, for example, a class called ExploderClass, and in C# do:

 using UnityEngine;
 using System.Collections;

 public class ExploderClass : $$anonymous$$onoBehaviour {
     //used with Invoke() to cause chained explosions 
     //to happen one after the other, rather than 
     //all simultaneously
     private const int ExplosionDelay = 0.1f;
     private const float ExplosionRadius = 2f;
     public Layer$$anonymous$$ask layer$$anonymous$$ask; //set this to whatever layers you want to get hit by the explosion

     //causes explosion to happen
     public void Explode() {
         //get all colliders this explosion will hit
         Collider[] colliders = Physics.OverlapSphere(transform.position,ExplosionRadius,layer$$anonymous$$ask.value);

         foreach (Collider c in colliders) {
             //get the ExploderClass script attached to the 
             //other collider, if any
             ExploderClass exploder = c.GetComponent<ExploderClass>();

             //call the other exploder's Explode() method to get
             //called after ExplosionDelay seconds. (Note: if
             //no ExploderClass script was found on c's
             //GameObject, this if statement doesn't run)
             if (exploder) exploder.Invoke("Explode",ExplosionDelay);
         }

         //Destroy this GameObject so it doesn't get re-exploded
         //by another exploder
         Destroy(gameObject);
     }
 }

Edit: fixed code formatting, added some more variables and using statements as needed, replaced SphereCastAll() with OverlapSphere()

avatar image adamchakov · Feb 25, 2014 at 11:27 AM 0
Share

hey @nesis thanks for the help but your script has errors , can u please test it =( ?

avatar image adamchakov · Feb 27, 2014 at 12:19 PM 0
Share

hey @nesis thanks a lot for editing the script , but where should i add this script , i added it to an object with a sphere collider , when i destroy the object , well nothing else that was inside the sphere gets destroyed , nothing was destroyed , thanks hope you'll reply ASAP

avatar image
0

Answer by kyrnal · Feb 25, 2014 at 01:11 AM

You could use a raycast from the first box to trigger the second box.

Physics.Raycast - Documentation

Also you can use the Vector3 shorthand to cast rays in many directions.

Vector3 - Documentation

Comment
Add comment · Show 4 · 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 adamchakov · Feb 25, 2014 at 01:42 AM 0
Share

hey @kyrnal thanks for the reply , tell me please , how can i use this script to destroy all the object tagged as "TNT" that are located inside this 100 meters ? thanks !

 function Update () {
         var hit : RaycastHit;
         if (Physics.Raycast (transform.position, -Vector3.up, hit, 100.0)) {
             var distanceToGround = hit.distance;
         }
     }
avatar image kyrnal · Feb 25, 2014 at 02:27 AM 0
Share
 // Note : the Integer "10" in the Physics.SphereCastAll line refers to the int value of the TNT layer.
 function Update () {
 
        var hit : RaycastHit;
        var hitColliders : Collider[];
 
        hitColliders = Physics.SphereCastAll (transform.position, 100.0, hit, 10);
 
        for (var objCollider : Collider in hitColliders) {
          objCollider.root.gameObject.SetActive(false);
        }
     }
     
avatar image kyrnal · Feb 25, 2014 at 02:29 AM 0
Share

I didn't test that, so it might error. But it could point you in the right direction, perhaps?

$$anonymous$$ister$$anonymous$$ike had the right idea with SphereCastAll

avatar image adamchakov · Feb 25, 2014 at 11:30 AM 0
Share

hey @$$anonymous$$yrnal thanks for the help but nop didn't work :/ it has an error : No appropriate version of 'UnityEngine.Physics.SphereCastAll' for the argument list '(UnityEngine.Vector3, float, UnityEngine.RaycastHit, int)' was found.

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

25 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Player object still gets destroyed even when shields up 1 Answer

If statement not working inside switch statement 1 Answer

Trigger explosion on rocket 1 Answer

Area of Effect damage trigger 2 Answers

How to trigger a particle effect? 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