Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

OnTriggerEnter on different targets during same "swing"?

Discussion in 'Scripting' started by CryptoJanne, Jun 13, 2020.

  1. CryptoJanne

    CryptoJanne

    Joined:
    Jul 7, 2019
    Posts:
    12
    Hello party people.

    I have an issue regarding my melee fighting system.
    Lets say i swing a sword with a script attached with OnTriggerEnter that deals damage when it enters a collider.
    My swing is a "double swing", meaning that it goes the same way back as it did forward, therefor hitting the colliders twice. To fix that i deal only damage once i add a boolean to only deal damage once.
    But what if there are two different colliders that get hit by my swing? right now i can only damage one, and i cannot figure out how to proceed.

    Thank you
     
  2. bitlysub2anf

    bitlysub2anf

    Joined:
    May 8, 2020
    Posts:
    71
    This is a give for take issue. I think that you should enable the double damage and because it hits twice, reduce the damage to half. If that's the case.

    Note: I am not an expert in melee games. That was just my personal opinion.
     
  3. CryptoJanne

    CryptoJanne

    Joined:
    Jul 7, 2019
    Posts:
    12
    Yeah, but its really not just twice it hits, i just wrote that for simplicity. Its more, give or take 5 times. I need it to be as i wrote :) thanks anyway
     
  4. CryptoJanne

    CryptoJanne

    Joined:
    Jul 7, 2019
    Posts:
    12
  5. TimmyTheTerrible

    TimmyTheTerrible

    Joined:
    Feb 18, 2017
    Posts:
    186
    How about have the attack keep a list of colliders it has hit. In on trigger enter check if the collider is already contained in the list. An animation event at the end of the swing could clear the list.

    Another option might be to have the damage not related to the collider on the weapon but to a damage zone trigger collider that covers the area of the attack.It would be enabled for a very short time at the climax of the attack.
     
    AllofPaul likes this.
  6. AllofPaul

    AllofPaul

    Joined:
    May 3, 2020
    Posts:
    2
    wow very creative solution, thanks! Using this 4 years later. :)