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 Dr_GeoFry · Oct 28, 2012 at 05:35 PM · destroyexplosiondetonatorimpact

Meteor Explosion, Destroy on Impact

Hi Guys,

First off, I know this is a simple question, and I have tried many tactics to get this to work, but I can't seem to get this working properly. I have been using the "Detonator-Insanity" Prefab to be the effect, but I get nothing.

So, what I want to happen is a meteor to fall out of the sky, explode on impact with the terrain, destroy itself, and once it explodes, I want to start a new reaction where it releases toxins and other interesting things.

I really only need help with the meteor exploding on impact and destroying itself. I use JS. I'm hoping for some code examples, as I have tried all the examples that I could find, and yet I still had no success.

Thank you for your help guys.

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 Dr_GeoFry · Oct 28, 2012 at 07:11 PM 0
Share

Thank you for your suggestion. I definitely have some basic knowledge of colliders, but I do not know anything about explosion commands. I just have not been able to make things work. I will show some scripts that I have used.

avatar image Dr_GeoFry · Oct 28, 2012 at 07:16 PM 0
Share

I tried approaching this from a health angle. I thought the meteor should have health, and when it hit the terrain, it should lose health. This is what I tried, and attached to the meteor, but it just hit the ground. No effect.

 var hp : int = 50;
 
 function Update (){
     if (hp==0){
         gameObject.GetComponent("Detonator").Explode();
         
         }
 }
 
 function OnCollisionEnter(collision:Collision){
     if(collision.rigidbody){
     hp = hp - 50;
     }
 }
avatar image Dr_GeoFry · Oct 28, 2012 at 07:20 PM 0
Share

I also found this code, but it did not work.

 // A grenade
 // - instantiates a explosion prefab when hitting a surface
 // - then destroys itself
 var  explosionPrefab : GameObject;
 var explodeSecs : float = -1;
  
 function Awake()
 {
     if (explodeSecs > 0) {
         Invoke ("DestroyNow", explodeSecs);
     }
 }
  
 function OnCollisionEnter( collision : Collision ) 
 {
     // Rotate the object so that the y-axis faces along the normal of the surface
     var contact : ContactPoint = collision.contacts[0];
     var rot : Quaternion = Quaternion.FromToRotation (Vector3.up, contact.normal);
     var pos : Vector3 = contact.point;
     Instantiate(explosionPrefab, pos, rot);
     // Destroy the projectile
     Destroy (gameObject);
 }
  
 function DestroyNow()
 {
     Instantiate(explosionPrefab, transform.position, transform.rotation);
     Destroy (gameObject);
 }

2 Replies

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

Answer by Jessespike · Oct 28, 2012 at 06:32 PM

I wouldn't recommended this method, but it'll probably work. Colliders would be a better choice.

 #pragma strict
 
 public var minimumYPosition : float = 0f;
 public var nextPrefabToLoad : GameObject;
 
 function Update () {
     if (this.transform.position.y < minimumYPosition)  
     {
         if (nextPrefabToLoad != null) {
             GameObject.Instantiate(nextPrefabToLoad, transform.position, transform.rotation);
         }
         Destroy(this.gameObject);
     }
 }

Edit

I don't know what a detonator is, a prefab that plays an animation clip? What does Expode() do? Where is the detonator, on the meteor or the explosion insanity? There's just not enough to go by on.

 function Update () {
     if (this.transform.position.y < minimumYPosition)
     {
         if (nextPrefabToLoad != null) {
             var explosion : GameObject = GameObject.Instantiate(nextPrefabToLoad, transform.position, transform.rotation);
             if (explosion.GetComponent("Detonator") != null) {
                 explosion.GetComponent("Detonator").Explode();  //detonator on explosion insanity                    
             }
         }
         //gameObject.GetComponent("Detonator").Explode();  // detonator on meteor
         if (this.renderer.enabled == true) Destroy(this.gameObject, 60f);
             this.renderer.enabled = false;
     }
 }
Comment
Add comment · Show 5 · 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 Dr_GeoFry · Oct 28, 2012 at 08:27 PM 0
Share

O$$anonymous$$, partial credit given. I know the code functions as it should in that this code causes the meteor to be destroyed, but no detonation is triggered, which is what I need to happen. Any assistance? I add the detonation-Insanity, but it does not get triggered on impact with the terrain. This has been my main problem the entire time.

avatar image Dr_GeoFry · Oct 28, 2012 at 09:37 PM 0
Share

So, the detonator, is a prefab. It contains a bunch of scripts with materials and particles attached to it. You can edit a bunch of the variables in these scripts. I just can't get the meteor to cause the detonator to trigger. Did you see my onCollision script? I just can't the meteor to explode. The detonator allows me to create the kind of explosion I want. But nothing is happening as of right now.

avatar image Jessespike · Oct 28, 2012 at 10:01 PM 0
Share

Ya i looked at the OnCollision code, I noticed, this:

gameObject.GetComponent("Detonator").Explode();

which may be causing a issue. If you look at my edit, you'll see I get the component from the instantiated object and not on the local gameObject.

avatar image Dr_GeoFry · Oct 28, 2012 at 10:06 PM 0
Share

what you say makes sense. let me check it out

avatar image Dr_GeoFry · Oct 28, 2012 at 10:20 PM 0
Share

O$$anonymous$$, I don't know why I said that I couldn't make it work before, but the OnCollide script works, it just doesn't throw out the explosion. It just destroys on impact. All the other scripts are the ones that do not work.

avatar image
0

Answer by Dr_GeoFry · Oct 28, 2012 at 11:53 PM

Not sure if I ever had a problem now. The explosion worked, it was just so small that I couldn't see it from the distance I was looking toward it. I created a camera and followed the meteor, and I saw it explode. Thank you all for taking the time to assist me.

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

10 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

Related Questions

Tank Missle Colide then explode and destroy 1 Answer

Explosion Elimination script 2 Answers

how can I destroying a spawn object ? 1 Answer

Detect explosion Character Controller 4 Answers

scripting Impact explosion 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