An interesting enemy behaviour change

I come up with a different solution to tweaking the enemy behaviour. The one showed in the video doesn’t cover any non-archer enemy, which will happily stand as stationary target for the player’s projectiles (unless you give everybody an extra long chase distance).

I added a hasBeenAttacked bool with a getter to Health. The bool is false by default and set to true when the enemy takes damage.
In the AiController I added an extra clause in Update that checks said bool and if it’s true, it multiplies the chaseDistance by a tunable amount (I did some tests to make it so that the distance is larger than the player’s projectile range). This way the moment the player shoots an enemy, the enemy starts chasing them no matter what their type is. It also leaves the door open for an ambush-like attack, where if you have a ranged weapon/spell that kill them in one hit, you can do that without alerting them first.

I realize that probably having Health raise an event to change the chaseDistance would be a better solution than checking the bool at each frame, but it felt a bit too elaborated for something that will probably be refactored again in some future lesson.

3 Likes

Good job on that. Our basic AI is just that, basic. There are lots of tweaks that can be made to make your characters “smarter”

wow thats a awesome idea dont mind if i yoink it :slight_smile:

I was thinking in a similar direction but also that the effect of having been hit should wear off after some time. I’m thinking it shouldn’t be the Health being responsible for it though…

This would go more along firing events, where TakeDamage() would fire an HasBeenHit event and that would register in the AI code to activate some “under alert” state which would increase the perception range for some time until it’s back to normal. So maybe there doesn’t have to be some specific counter somewhere for it but just having a maximum chase distance that would be reduced to the regular one over time…
I wouldn’t want to have a flag on the Health to be polled all the time either. OTOH one might add some bleeding or similar and could have the “under alert” active while the wound’s still bleeding, or something… :thinking:

It’s probably something to keep in mind and revisit later when some more systems are in place that allow healing for example. A possible design decision might be to think about whether enemies might be able to heal over time, as well…

Privacy & Terms