Search Unity

How do I do proper melee combat

Discussion in 'Community Learning & Teaching' started by PrecisionGaming, Aug 14, 2014.

  1. PrecisionGaming

    PrecisionGaming

    Joined:
    Nov 6, 2013
    Posts:
    6
    I'm a total unity noob, how exactly do I use animation for hit detection. I have no clue. I'm trying to make a chivalry/mount and blade type system. I really have no clue at all. Not even sure how to make a rigid body. please help
     
  2. DoubleLee

    DoubleLee

    Joined:
    Apr 11, 2014
    Posts:
    34
    Hi. I recently implemented my own system for combat. I won't go into every detail but I will explain how in a nut shell.

    First you place your weapon on the hand object of your character. I put a box collider as trigger, and a rigid body as kinematic on my weapon object. Also whatever you are planning on hitting with your melee like enemies need some kind of colliders to hit.

    Using mecanim I placed 2 events on my attack animation AttackBegin and AttackEnd events. Attackbegin simply turns a bool in my player script to true, which tracks when the swing is happening, and AttackEnd turns the bool false.

    This will create a system where this bool will only be true when you are swinging your sword.

    On the weapon you create a script and do your damaging code in OnTriggerEnter/Stay, but only if that attack bool is true. If a valid hit was detected, set the attacking bool to false, so only 1 hit can happen per swing.

    Good luck my friend. There are lots of ways to do this so pick the technique that works for you and your game.
     
    samurai926 likes this.
  3. PrecisionGaming

    PrecisionGaming

    Joined:
    Nov 6, 2013
    Posts:
    6
    Alright I understand what I need to do, i have colliders on my sword and enemy, and the enemy collider is set as a trigger. What line of code do I use? I've tried OnTriggerEnter, but it doesn't work. I'm sure that I just wrote it wrong, but I can't find much online. Thanks for the reply.