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. Dismiss Notice

strategy for collision detecting of a melee attack

Discussion in 'Scripting' started by scifresh, Sep 1, 2020.

  1. scifresh

    scifresh

    Joined:
    Oct 8, 2013
    Posts:
    23
    Hi everyone,

    I am currently having a problem that occurs when I try to detect collisions of an attack animation. I am using unity and have a 3d model. I added an empty game object to the models hand and attached a collision collider with istrigger checked. In the animation I ve created two events: OnBeginAttack and OnEndAttack. These events activated and deactivate the collider. I have another 3d model with a capsule collider. When I play the animation with empty hands (no weapon, just the a sphere collider as big as the models hand) I get the hit detection only on the left hand and not always. If the player is too close to the enemy, the hand goes through it and does not trigger collided event.

    I have also tried another approach: I removed all the colliders and created OnHit animation event. When this event occurs, I create a sphere collider programmaticaly. This produced same results (sometimes even worse).

    How do you guys handle this ? How do you setup melee attack system ? I have different types of weapons but also unarmed animations like boxing and kicking. I would appreciate any ideas.
     
    Last edited: Sep 1, 2020
  2. Yoreki

    Yoreki

    Joined:
    Apr 10, 2019
    Posts:
    2,590
    I can change my font size too! :)
    Are your colliders by any chance already inside the collider of the enemy. This is implied by it not working when you are too close to the enemy.
    Maybe use an OnTriggerStay and print some Debug.Log message.
     
  3. scifresh

    scifresh

    Joined:
    Oct 8, 2013
    Posts:
    23
    Sorry about that, changed the font back to normal. I found my answer in this video:
     
    trombonaut and Yoreki like this.