Game Development Asked by Kit K on February 3, 2021
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.
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.
Answered by Kit K on February 3, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP