Making Enemies That Try And Dodge The Player’s Attacks

In a lot of games, you will encounter enemy AI that detects the player’s actions and tries to counter them. In Halo if you throw a grenade, the Elite enemy type will attempt to dive out of the way in order to avoid taking damage. So what would that logic look like?

In order for an enemy to react, they will need some sort of trigger to react to. In this case, I am using the same colliders that I used/addressed in a previous article for enemies to detect powerups that are in front of them. I then just added an alternative method that is called in Update instead of the regular movement calculations if a laser is detected in front of them.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store