Control melee attack damages during animation

Riddick

New member
Hi,

I'm developping a game with melee attacks. I want be able to controle when the weapon (sword) can damage ennemies during the animation.
1) At the start of the animation i want the damages are OFF because my character charges his sword attack, and i want prevent he hits ennemies in his back.
2) Then i want the damages are ON during the attack.
3) At the end i want the damages are OFF again to prevent damage if an ennemie touch the sword while the player animation ending.

On the meleeWeapon script, there is the variable canHitDelay which could do the job, but i need the delay depend of the animation and not depend of the weapon. Moreover this does not solve the 3).

I added events on the animation to know when damages should be active or inactive
ucc_1.png

And i created a class to received events

C#:
public class MeleeWeaponOverride : MonoBehaviour
{
    private bool canDamage = false;


    public void AttackDamageOn()
    {
        Debug.Log("Sword damage ON");
        canDamage = true;
    }



    public void AttackDamageOff()
    {
        Debug.Log("Sword damage OFF");
        canDamage = false;
    }


}

Im' stuck on the last part, make the weapon "inactive" when canDamage == false.
How can i do that ?

Thanks in advance for the help.
 
Last edited:
You could override UseItemUpdate and return early when can damage is no longer true.
 
Works good ! Thank you Justin.
Have you any idea why the inspector visualization of an overrided script does not show properly ?

My overrided class :

C#:
using Opsive.UltimateCharacterController.Items.Actions;
using UnityEngine;

public class MeleeWeaponOverride : MeleeWeapon
{
    private bool canDamage = false; 

    public void setCanDamage(bool m_canDamage)
    {
        canDamage = m_canDamage;
      
    }

    public override void UseItemUpdate()
    {
        if (canDamage)
        {
            base.UseItemUpdate();
        }
        else
        {
            return;
        }
    }
}


Inspector visualization :

1601978682207.png
 
Most UCC components use custom inspectors (i.e. MeleeWeaponInspector.cs), so I imagine it's using that inspector for your subclass. You'd need to create a custom inspector for your subclass in that case.
 
Top