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 kmgilbert100 · Jan 24, 2012 at 02:10 AM · collisiondestroyexplosioncollisiondetectiondetonator

Tank Missle Colide then explode and destroy

Well I have been trying to do this for few hours now... What I want to happen is I want the missile a sphere in the video when it collides with something I want to to explode using the simple detonator from the detonator prefab provided by unity. After that I want it to "destroy"... This is as far as I got but of course it did not work. I am very confused on how I have to set this up... Video and the code is below.

http://forum.unity3d.com/threads/120389-Tank-Game-Scripting-Fire


The code that was in the video var projectilPrefab : Transform; var powerOfShoot : float = 3000;

function Update () { if(Input.GetButtonDown("Jump")){ audio.Play();

     var projectil = Instantiate(projectilPrefab, transform.position, transform.rotation);
     projectil.rigidbody.AddForce(transform.forward * powerOfShoot);
 }

}


The code that I tried but did not succeed var projectilPrefab : Transform; var explosionPrefab : Transform; var projectildes : Transform; var powerOfShoot : float = 3000;

function Update () { if(Input.GetButtonDown("Jump")){ audio.Play();

     var projectil = Instantiate(projectilPrefab, transform.position, transform.rotation);
     projectil.rigidbody.AddForce(transform.forward * powerOfShoot);
 }

} 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 (projectildes); }

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Lo0NuhtiK · Jan 25, 2012 at 06:46 AM

Looks like you need two scripts to me. One on-gun for shooting , one on-projectile for collision.

ShootScript

var projectile : Rigidbody ;
var powerOfShoot : float = 3000 ;
 
function Update(){
   if(Input.GetButtonDown("Jump")){
      audio.Play() ;
      var clone : Rigidbody ;
      clone = Instantiate(projectile, transform.positon, transform.rotation) ;
      clone.rigidbody.AddForce(transform.forward * powerOfShoot) ;
   }
}


ProjectileScript

var explosion : Transform ;
 
function OnCollisionEnter(other : Collision){
   var contact : ContactPoint = other.contacts[0] ;
   var rot : Quaternion = Quaternion.FromToRotation(Vector3.up, contact.normal) ;
   var cloneExplode : Transform ;
   cloneExplode = Instantiate(explosion, contact.point, rot) ;
   Destroy(gameObject) ;
}
Comment
Add comment · Show 2 · 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 kmgilbert100 · Jan 26, 2012 at 01:25 AM 0
Share

Where it says " Destroy(gameObject) ;" do i replace gameObject with somthing?

avatar image idiot333 · Feb 19, 2015 at 01:12 PM 0
Share

@kmgilbert100 come-on man you have no knowledge of functions and objects in unity. don't just cram up everything and find scripts here and there. you need to learn things yourself and learn the basics first.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Shuriken Explosion Example - Collision 0 Answers

Unity Detonator - Detect Shockwave on Object 0 Answers

Objects do not destroy on Collision 1 Answer

Explosion Elimination script 2 Answers

Different Explosion for Different Collisions 3 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