Language

Adding multiple attack animations to enemy AI. can anyone help me?

Ok so I searched around for this and didn't turn up anything on here nor google. I have an enemy with 6 attack animations and an AI script for him. What I want to do is when he attacks he chooses a random attack to do from the script.

1 Reply

you're using semaphores (bool) to check if enemy is closed to player, I prefer state mchines, if possible inside a corroutine, but well, to know when attack... we will use bool facing; to determine that, since it not have a comparer with distance + rotation between enemy and player,
so to enable "facing" add on FaceTarget

well, once we know it almost rotate to the player, add a transition on animator, but type int,
now buid the code of the AttackTarget() using a int transition, and add a global variable int typeattack = 0

then on the animator build a state for each animation of atack, build transitions to each attack state with a different value of "attack" (from 1 to 6), and a void transition to return (will return when finish attack) to disable de attack, you need to do it once translated u can do it managing the variable attack on each animation, setting it to zero once finised (if u use that idea, set variable "has exit time" as false from animator on all transitions to evade problems) or manage to change it once started the attack animation (more useful if you add damage by script) u can do it on the next iteration setting it to 0 on each update before doing anything else, some like