How do I create a Ranged enemy A.I?

I really want to know how to make an A.I that shoots projectiles at the player at a distance with following the Player at a Certain Distance…

Hey there,

This is a very complex question, so first of all, i recommend learning the basics of AI using behavior trees and blackboards.
Unreal’s Youtube channel contains many many tutorials about this.
If you feel you need something much more specific, i recommend maybe the following tutorials (NOTE: Pluralsight does give trial period but otherwise costs around 29$ a month):

Pluralsight’s intro to AI navigation

Pluralsight’s AI Behavior states

I found these tutorials to be very helpful, but there are many free alternatives.

Now, about your question, i can only give you the general logic:

You need to create an enemy character with an enemy AI controller. Create a blackboard and a behavior tree. Make the AI Controller run the behavior tree on EventBeginPlay.

Your behavior tree can be split up to multiple AI States, like “Idle”, “Looking for enemy” and “Seeing enemy”.

Afterwards, add an AIPerception component to your AI character and add a AIStimuli component to your player character. Make sure to add the exact senses to both AIPerception and AIStimuli.

Then, use the AIPerception functions to detect when a player is visible and when he is no longer visible.

If no enemy visible → AI is Idle

If Enemy is visible → AI is Seeing Enemy

if Enemy was visible but no longer → start a certain timer to allow a short “search” timer and AI will be in Looking for Enemy state.

In your blackboard:

Idle can be a very basic "Wait X seconds).

Looking for enemy can be a MoveTo(lastKnownLocation) and then Wait Y seconds.

Seeing Enemy should be MoveTo(EnemyActor) until is in MinimumRange then Shoot which will be the AI Character doing all the animations and trace calculations for the shooting.

NOTE: this is as specific as possible but still very general. You need to know how to use Blackboard variables and key selectors to achieve this. So, again, i recommend learning the basics first :slight_smile:

Hope this was helpful.

You can also try the free tutorials of ShooterTutorial.com.

This specific one explains just what u wanted: Shooter Tutorial first enemy BT