AI shooting at player

I am trying to make the AI to shoot at the player when he see the player.Can someone help me?

So this can get to be a little complex, but I’ll try to explain it in it’s simplest form, not using Behavior trees. This will get you up to the point of Having an enemy able to actually see you. From there, I’ll go into concept/workflow preference.

  1. When you’re creating your character, you want to make sure it is in fact a character. In blueprint, you would add blueprint > character. This gives you access to something called “pawn sensing,” a basic sensory component that you can add to the AI Character. So, now let’s do exactly that.

  2. Once your character is created, the little blueprint icon for it (if it’s a “character” will be a body inside a pill. This is exactly what you want. Double click it, and it’ll open up the editor for this particular Bp. In there, you have the components tab, and a big green button that says “+ add component.” Go ahead and hit that bad boy, and type in “sensing” into the search bar, and add the “pawn sensing” result.

  3. from there, highlight the pawn sensing, and scroll down to the bottom in it’s details bar, to events. You want to add the “On See” Pawn" event. This little guy is going to be your bread and butter here.

  4. Now that we’ve got the “I’ve been spotted” event, it’s time to tell the enemy -what- to spot. This part is pretty straightforward. You want to drag off the See pawn executable pin, and create a cast to character node. Make sure to connect the “Pawn” pin on the event into the “Object” pin (both blue) of the cast.

  5. From there, you now have it ready to respond to the player, whenever the player is “in view.” But it doesn’t do anything yet. At this point, I like to add a “print string” node that updates me when I’m “in view.” This helps to keep track of whether it does see me or not.

But what you want to do now is where it gets kind of complex, and to taste… So while this does give you the platform to spring from, I’ll go into -my- workflow for an example. This isn’t so much step by step as it is explaining the “how” of it. There are MANY great tutorials that cover all of this next part, explained far better than I can ever do.

My workflow:

I add a sequence node process off the cast, where the first is a look at(using get actor location/find look rotation nodes connecting into a set actor rotation node)

At, the second is a move to (there’s a node specifically for this called "AI MoveTo),

And the third is “If in range, fire” (I use the BP_Projectile from FPS template here to fire, I use a sphere as the trigger box for the if in range bit, and bools to toggle in range, or not Create a separate “On Actor Begin Overlap” as well as “On actor End Overlap” for the sphere, and have it tick true/false in the bool.) And Voila. A “Good Enough” AI.

Now… Behavior trees are a much better route for this, to be certain, however… The above should give you a really good launching point if you wanted to do it purely in BP, and be able to Drag and drop these guys onto the map for a quick, usable AI.

Further topics to read to create more advanced AI is, again… Behavior trees.
Further topics to read to create more advanced Firing systems, line tracing.

.