0
\$\begingroup\$

I'm having an issue with my animator for an enemy, where a bite animation should trigger when the enemy collides with the player. Weirdly enough, the sound effect for the bite activates, but the trigger doesn't change.

It only works in start for when I set the initial trigger, but I can do that in the animator tab anyway, so it's unnecessary.

There is only one major hitch I can think of, which is that the player's collider isn't set as a trigger, but for some reason the game detects the collision anyway when I put a debug.log in to see if it's working.

Nothing is popping up as an error in the console.

Here is the code. Ignore anything that's commented out, as it's not commented out in my version. It's just for the sake of posterity.

void OnTriggerEnter(Collider other)
    {
        //if (other.gameObject.CompareTag("Melee"))
        //{
        //    PhysicalAttack physicalAttack = other.GetComponent<PhysicalAttack>();
        //    if (physicalAttack.attack == true)
        //    {
        //        physicalAttack.attack = false;
        //        //Debug.Log(physicalAttack.attack);
        //        Damage(physicalAttack.damage);
        //        transform.Translate(0, 0, -5);
        //    }
        //}
        else if (other.gameObject.CompareTag("Player") && canAttack)
        {
            Debug.Log("collision");
            Animator anim = gameObject.GetComponent<Animator>();
            //fishHealth fish = other.gameObject.GetComponent<fishHealth>();
            anim.ResetTrigger("Not Attacking");
            anim.SetTrigger("Attacking");
            //fish.currentPlayerHealth -= 10;
            GetComponent<AudioSource>().clip = Bite;
            GetComponent<AudioSource>().Play();
            //StartCoroutine(DamageDelay());
        }

Here are some screenshots of info from the animator.

enter image description here

enter image description here

New contributor
Kit K is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
\$\endgroup\$
0
\$\begingroup\$

EDIT: issue was actually in a different function, where I called a startcoroutine that was supposed to prevent the enemies from doing huge swaths of damage on consistent collisions. The coroutine turned a bool to false for several seconds, and the same bool was being used for the activation of the animation if it was true.

| improve this answer | |
New contributor
Kit K is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
\$\endgroup\$

Your Answer

Kit K is a new contributor. Be nice, and check out our Code of Conduct.

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.