Adapting the Enemy Attack State

I created a slightly more complex attack system that uses scores for various attacks giving higher score attacks a greater chance of occuring. I also gave enemy attacks a cooldown. This adds a bit of variability to an AIs attack and it also checks if the player is in the right angle for the attack, meaning it won’t try to use the attack if the player is behind. Each attack can be individualized to have a specific range and angle. The AI can also rotate to a certain degree during their attack animation, I feel like this gives them a bit more life when they swing instead of being frozen in one direction during the whole animation and you can really tweek this to your hearts content. I might add a force applier too, similar to the player, for some of my animations that involve essentially root motion movement however we don’t use root motion so those animations sometimes look silly when their is no actual movement… I don’t think it would be hard at all to add since we already did it for the player.

Oh, you can also specify what damage collider you want for each attack, so you can have multiple different colliders, maybe for a big AoE attack around the enemy that you can turn on and off, instead of just one that is attached to a weapon. This is why my script is also called “AttackHandler” instead of having a weapon handler, because its handling the cooldown times and which collider should be activated as well as how much damage it should do when it collides.

This is a screenshot of my skeleton enemies inspector and you can see these settings here.

Anyway, I just wanted to show off some of the changes i made. Hopefully it doesn’t make the series to difficult to follow along with.

You might consider putting these into a ScriptableObject which can then be assigned to the Enemy Attack Handler… It’s one extra layer, yes, but what it does is make it so that you could create another enemy with a different model, but then easily link the ScriptableObject.

When the game starts, you could copy the data from the ScriptableObject into your existing script in Start or Awake, or you could simply pull the data as needed directly from the ScriptableObject.

2 Likes

Great Idea brian, thank you! I think i will go that direction when I start having a few too many monsters.

I tried applying a force to the AI attack but it didn’t turn out the way I wanted.

Out of curiosity, how hard do you think it would be to use root motion for attacks?

So what I did was during entering the attack state I disabled the agent and enable apply root motion on the animator, and on exit of the attack state I reset these. I think that has had the intended effect of allowing root motion attacks but keeping the movement within the character controller. What do you think?

That’s exactly what I was about to suggest.

2 Likes

Its working out pretty nice and making for much more soul’s like /elden ring sort of attacks, its awesome!

Privacy & Terms