enemy detecting player fire

Hello everyone, I’m working on getting an enemy AI to dodge to the left or right when they are shot at, I tried setting up a global Boolean variable would set it’s self to true in the player code, every time the fire button is pressed, but the enemy just sits there, any suggestions on getting AI to know when do dodge

Have a boolean set up in the enemy Ai script and when the fire button is pressed just have the boolean be set to true using getcomponent.

I would imagine the bullet moves slow enough that we can see it. When you fire the bullet, use a raycast to see if it hits an enemy and if it hits and enemy (the ray, not the bullet) have it trigger that enemy to move. Then, as long as that enemy is true, have it check for bullets until it is no longer true.

This doesn’t cover leading shots, but we can get that next.

Astrauk and JRavey thanks for the fast response.