1
\$\begingroup\$

i have some issues about my attack animations right now, i'm doing my light attack which has 3 separate attacks and animations. the scripting and trigger works(without animation), but my animation just doesn't keep on playing from 1st to second to last attack, however, the boolean for the animator seems to work properly. i've set their transitions' interruption as "current state then next state". as i wanted to make the trigger "in sync" with the animation, i've set my boolean to false as the trigger disabled. I'm new with the animation, so i might need some advise for animating if avaliable edit: want to know if it's possible to refer other gameobject/children/parents in animation? as i would like to refer the trigger outside the object with animator component.

images show's the current animator tree and it's parameter, which combo attacks places as L_Attack

public class playerAttack : MonoBehaviour {
private bool attacking = false;
private bool heavyAttacking = false;
public KeyCode lightATK;
public KeyCode secondATK;
public KeyCode finalATK;
public KeyCode heavyATK;
private float comboResetTimer = 1f;
private int combo = 0;
private float comboTimer = 0f;
//private int attackcheck =0;

private float attackTimer = 0;
private float attackCD = 0.3f;
public Collider2D lightAttackTrigger;
public Collider2D comboAttackTrigger;
public Collider2D comboFinishTrigger;
public Collider2D heavyAttackTrigger;
public bool firstATK = true;
public bool SecondATK = false;
public bool thirdATK = false;


private Animator anim;


void Awake() {
    anim = gameObject.GetComponent<Animator> ();
    lightAttackTrigger.enabled = false;
    comboAttackTrigger.enabled = false;
    comboFinishTrigger.enabled = false;
    heavyAttackTrigger.enabled = false;
}

// Update is called once per frame
void Update() {


    if (firstATK)
    {
        if (Input.GetKeyDown(lightATK) && !attacking) {
            attacking = true;
            attackTimer = attackCD;
            comboTimer = comboResetTimer;
            combo += 1;
            firstATK = false;
            SecondATK = true;
            lightAttackTrigger.enabled = true;


        }

    }

    if (SecondATK)
    {
        if (Input.GetKeyDown(lightATK) && !attacking)
        {

            attacking = true;
            attackTimer = attackCD;
            comboTimer = comboResetTimer;
            combo += 1;
            SecondATK = false;
            thirdATK = true;

            comboAttackTrigger.enabled = true;


        }

    }

    if (thirdATK)
    {
        if (Input.GetKeyDown(lightATK) && !attacking)
        {

            attacking = true;
            attackTimer = attackCD;
            comboTimer = comboResetTimer;
            thirdATK = false;
            combo += 1;


            comboFinishTrigger.enabled = true;


        }
    }

    if (attacking) {
        if (combo == 1)
        {
            Debug.Log("nico");
            if (attackTimer > 0)
            {
                attackTimer -= Time.deltaTime;
                anim.SetBool("LightAttacking", true);
            }
            else
            {

                    attacking = false;
                    lightAttackTrigger.enabled = false;

              // anim.SetBool("LightAttacking", false);



            }
        }

        if (combo ==2)
        {
            Debug.Log("NICO");
            if (attackTimer > 0)
            {
                attackTimer -= Time.deltaTime;
                anim.SetBool("2ndLAttack", true);
            }
            else
            {

                    attacking = false;
                    comboAttackTrigger.enabled = false;
               anim.SetBool("2ndLAttack", false);


            }
        }

        if (combo == 3)
        {
            Debug.Log("NI!!!!!!!");
            if (attackTimer > 0)
            {
                attackTimer -= Time.deltaTime;
                anim.SetBool("FinalLAttack", true);
            }
            else
            {

                    attacking = false;
                    comboFinishTrigger.enabled = false;
                comboTimer = 0f;

                anim.SetBool("FinalLAttack", false);

            }
        }
    }

    if (comboTimer > 0) //count down tombo timer
    {
        Debug.Log("counting...");
        comboTimer -= Time.deltaTime;

    }
    else
    {
        combo = 0;
        //Debug.Log("Combo Reset");
        firstATK = true;
        SecondATK = false;
        thirdATK = false;

    }

        if (Input.GetKeyDown(heavyATK) && !heavyAttacking) {
        Invoke("heavyAttack", 0.5f);

    }
    if (heavyAttacking) {
        if (attackTimer > 0) {
            attackTimer -= Time.deltaTime;
        } else {
            heavyAttacking = false;
            heavyAttackTrigger.enabled = false;
        }

    }



}
void heavyAttack()
{
    heavyAttackTrigger.enabled = true;
    heavyAttacking = true;
    attackTimer = attackCD;
    Debug.Log("Heavy Attacked");

}

}

\$\endgroup\$
0
\$\begingroup\$

so instead of linking these animation together, these attack animations should be transits with any state, with can transition to self unchecked

enter image description here

\$\endgroup\$
  • \$\begingroup\$ If you would explain why this is necessary, I would upvote this answer. \$\endgroup\$ – Philipp Sep 9 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.