Unity Community


Results 1 to 5 of 5

  1. Posts
    578

    destroy on collision

    hey everyone.. im having some issues with getting my missile to be destroyed on its collision..

    Code:  
    1. function OnCollisionEnter  (collisionInfo : Collision);
    2.  
    3. if (collisionInfo.gameObject.tag == ("block")
    4. {
    5. Destroy(gameObject);
    6. }

    thats the script i have attached to my missile, "block" is the tag of an item it will collide with


    any help?
    3d Modeler, Animator, and Developer

    Download Bird Poop for for Free! Click Below!
    Bird Poop Android!
    Bird Poop iOS!

    Online Portfolio at www.patsommer.com


  2. Location
    Lognes, France
    Posts
    1,149
    It does not trigger ?

    Check whether the gameObjets with tag "block" also have a collider AND whether one or both of the objects have a rigidbody (IsKinematic off).

    http://unity3d.com/support/documenta...l/Physics.html
    A lazy big fat chicken hibernating, sleeping peacefully.
    !


  3. Posts
    578
    thanks i actually just figured it out tho... i was making it way more complex then it had to be... simple enuff put this code on the missile prefab

    Code:  
    1. function OnCollisionEnter () {
    2.  
    3. Destroy (gameObject);
    4.  
    5. }

    works like a charm
    3d Modeler, Animator, and Developer

    Download Bird Poop for for Free! Click Below!
    Bird Poop Android!
    Bird Poop iOS!

    Online Portfolio at www.patsommer.com


  4. Location
    Sarasota, FL
    Posts
    244
    You rewrote your script, right? I don't think it would run that way. Here's what I expect will run:

    Code:  
    1. function OnCollisionEnter  (collisionInfo : Collision) {
    2.     if (collisionInfo.gameObject.tag == ("block")
    3.     {
    4.         Destroy(gameObject);
    5.     }
    6. }

    And just to check that everything is triggering when it ought to, try this:

    Code:  
    1. function OnCollisionEnter  (collisionInfo : Collision) {
    2.     Debug.Log("collision occurred");
    3.     Debug.Log("tag = " + collisionInfo.gameObject.tag);
    4.     if (collisionInfo.gameObject.tag == ("block")
    5.     {
    6.         Destroy(gameObject);
    7.     }
    8. }

    Also, check the "collision detection matrix" (on the page AkilaeTribe referenced) to make sure the missile object type can bump into the block object type.
    - Brett -
    available for consulting gigs
    CreatedByBrett.com


  5. Location
    Sarasota, FL
    Posts
    244
    Aw man, I was writing while you were figuring it out. Never mind.
    - Brett -
    available for consulting gigs
    CreatedByBrett.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •