Ai turret attacking AI

Hello, I have been working on a turret blueprint that attacks Ai Zombies that run past it. I have made it target the zombies via a operlap event however, when the first target is dead it ignores the AI already in the area and waits for a new zombie to enter. How would I go about having the turret attack anything already in the area?
I’m using Blueprint for this as I’m not a coder.

Thanks in advance.

You should add a pawn sensing component configure it and rely on its callbacks to notify you of the AI.

This will remove the requirement of the overlap event being your notify system. Which as you have discovered is not reliable in this configuration.

Pawn Sensing should get you started.

Ah thanks very much. The asset is currently set as character, using the ‘Character movement’ componenet, what would be the closet to this node in pawn?.

Thanks :slight_smile:

I was going to type it all out but it seemed like a lot of work. I am basically checking which one is closest and setting that distance. I am also checking to see if they have a tag of “Target”. Then I just added in some check variables, Target is the closest actor with the tag of “Target”. “Closest” is the distance to the “Target”. “Has Target” just makes sure that there is a target in range. My max range is 3500 and is set to tell the “Has Target” whether it is true or false depending on the closest target. Then I just do a “Is Valid” to make sure the target isn’t dead. The other “Get Distance To” is actually to keep the turret from targeting outside the range I want. Otherwise it would literally fire until the target was dead. I chose to use the distance instead of a collider but you could always use a collider. The two other scripts are special for my turret. I don’t have a skeleton on it and Rotate Turret just rotates the actor.

The Aim will independently aim the Turret Muzzles and adjust the Turret Base.

This is just a “Patrol” Function. It basically just rotates the turret when no targets are present.

I really hope this helps. It was a pain in my back side for a while. If you need to see how I did firing just let me know.