Search Unity

OnTriggerEnter Method doesn't work (Solved)

Discussion in 'Getting Started' started by Arkeith, Jul 22, 2020.

  1. Arkeith

    Arkeith

    Joined:
    Aug 4, 2018
    Posts:
    3
    Hello everyone,

    I am currently doing the Prototype 2 from the "Create with Code Live Summer".
    I did everything the Tutorial told me to do:
    I put the Box Collider on every animal (Object), edited the Collider so it really covers the whole object (width, height and depth) and checked the "IsTrigger"-box. I also did add the Rigidbody-component to the projectile. At the end I attached the script to every animal (Object):
    Code (CSharp):
    1.     private void OnTriggerEnter(Collider other) {
    2.         Destroy(gameObject);
    3.         Destroy(other.gameObject);
    4.     }
    I even made the Animals (Objects) really big and checked the Scene from different Viewpoints, so that i can really assure, that my projectile is hitting or in my case, flying through the animals.
    I also restarted the whole project/Unity, without any success. I also checked that the objects/prefabs had the right components/scripts while the game was running. I am at my end and would apprechiate any help!
     
  2. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    Do the projectile objects have a trigger collider as well? They'd need one if not.
     
    Arkeith likes this.
  3. Arkeith

    Arkeith

    Joined:
    Aug 4, 2018
    Posts:
    3
    Thought that the trigger collider on the projectile isn't needed since I had the Rigidbody on them.
    But I also tried putting the same Box Collider + IsTrigger checked on the Player himself and it didn't work.
     
  4. Vryken

    Vryken

    Joined:
    Jan 23, 2018
    Posts:
    2,106
    Rigidbodies just allow a GameObject to interact with the physics system, but they do not provide any collision functions themselves.
    Colliders only collide with other colliders.

    You tried making the player collide with an animal or with a bullet?
     
    Arkeith likes this.
  5. Arkeith

    Arkeith

    Joined:
    Aug 4, 2018
    Posts:
    3
    Oh thank you so much, Vryken.
    I might have really forgot to set "Istrigger" on the player.
    I tested and both the projectile and/or the human are dissapearing on collison.
    I see that I overread this section:
    1. Repeat this process for each of the animals and the projectile.
    This thread can be closed!
    thread.Stop();
     
    Vryken likes this.