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 userpay · Oct 31, 2010 at 03:58 PM · destroyexplosionmissile

Missile Collision and Explosions

Okay so I want to make it so that when my missiles collide with something they explode(terrain, object, ect), how would I set this up? Note I have downloaded the Detonator extension.

Currently I've got targets that go down just from getting hit, how would I arrage for the explosion made (most likely would use either the simple or tiny explosion if I use a premade one) to be what knocks the targets down?

And if you would so kindly provide some example code for the above questions? I'm just barely starting out using Unity so if you just tell me where to put it I might not quite get it. Thank you ahead of time.

Comment
Add comment · Show 1
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 KrisCadle · Jul 26, 2011 at 10:30 PM 0
Share

Here's something i copied from a longer script i wrote for a game. Basically the idea is you put this on your missile prefab and then when you instantiate it from a button or whatever it will fly forward on its Z axis and at whatever speed you put in the code (right now it's set to 100) Then when it hits something it will explode and destroy itself. It can also do something depending on what the Tag is of the object it hit (like add different scores for different objects)... I have not tested this exact script but it will point you in the right direction ;)

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by KrisCadle · Jul 26, 2011 at 10:25 PM

     //attach your explosion prefab in the editor 
     
     var explosion : GameObject;
     
     static var score : float;   
         
         
     //gives the missile its speed
 
 function FixedUpdate () {
     
            rigidbody.AddForce (transform.TransformDirection (Vector3.forward) * 100.0);
     
         }
         
         
     function OnCollisionEnter(collision : Collision) {
         
             var contact : ContactPoint = collision.contacts[0];
             var thisExplosion : GameObject = Instantiate (explosion, contact.point + (contact.normal * 5.0) , Quaternion.identity);
         
 //here you can set a tag so when your missile hits different stuff it can add different scores or have different explosions
         
             if (collision.gameObject.tag == "enemy")
             {
             score = score + 100;
             Destroy (collision.gameObject);
             
             Instantiate (explosion, contact.point + (contact.normal * 5.0) , Quaternion.identity);
             
             }
         
         }
         
         Destroy (thisExplosion, 2.0);
         Destroy (gameObject);
             
             
         }
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

2 People are following this question.

avatar image avatar image

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

OnTriggerEnter - destroy (this.gameobject) if it collides with anything 2 Answers

How to emit particle from a collision? 2 Answers

destroy bullets script! 1 Answer

Instantiate spawns 2 instead of 1, help? 2 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