Search Unity

Fireball not destory when touching wall a bit, but destroy when totally hits wall (OnTriggerStay ?)

Discussion in 'Physics' started by Firlefanz73, Dec 15, 2017.

  1. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    Hello,

    my wizard is Shooting a FIREBALL, which has a sphere collider and it's own class.

    When the FIREBALL hits a wall but only touching it a Little bit, I would like to continue, but when it totally flies straight into the wall, I want to destory it.

    This Code is working so far that the FIREBALL is destroyed every time, how can I have it continue when it just touches it a bit?
    Code (CSharp):
    1.  void OnTriggerStay (Collider other)
    2.  {
    3.   //Debug.LogWarning (string.Format ("Bullet Triggerstay with {0}", other.gameObject));
    4.   if (!other.gameObject.CompareTag ("Monster") && !other.gameObject.CompareTag ("Animal") && !other.gameObject.CompareTag ("FurBall")) {
    5.    Destroy (gameObject);
    6.   }
    7.  }
    Thanks a lot :)
     
  2. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,243
    Make the fireball's collider smaller.
     
  3. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    Then it is harder to hit Monsters or it Looks like hitting Monsters, but it does not.
    Or not?
     
  4. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,243
    How about separate collider for walls and for monsters?
     
    Firlefanz73 likes this.
  5. Firlefanz73

    Firlefanz73

    Joined:
    Apr 2, 2015
    Posts:
    1,316
    Good idea. I just tested I can have two colliders in one object, put them into public variables and check each one then.
    I will add a smaller one for walls!

    Thanks for the idea :)