How to make helpful AI

Hi everyone I am making an fps game and I was hoping someone could help me with AI specifically AI that helps the player such as Picking up weapons, killing zombies, ducking for cover hiding in buildings etc. but I have no idea how to start could someone please help?? any help is appreciated, thanks in advance :slight_smile:

I also forgot that the ai needs to be able to punch zombies if they are close enough any help again is appreciated :slight_smile:

Your question covers a lot of topics. You could start learning the basics of Unreal AI by going to the Unreal Engine web site and looking up Live Training videos which give step by step examples of how to use the AI stuff in the official documentation. It’s on youtube also. For example the Game Ready ai in unreal videos show you how to make basic navigation, Behavior Trees, environnent queries etc.

If you just need the ai to simply pick up every nearby pickuppable item and fight every nearby enemy then you can probably get by without anything too fancy - might not even have to learn Behavior trees etc.

What if I wanted the AI to pickup an item randomly so it doesn’t pickup every item?

Does it need ro be smart about its choice or just say “I can reach 5 items without straying too far from the player. I think I’ll pick…” *rolls dice to decide * “…that one!”. ?

probably smart?

Anyone who can help me??

There’s a youTube video that explains how to make AI smarter about which items or enemies it wants to chase.
It is very extensive though and I am not sure you need that level of detail, but it is called Unreal Live Training Game Ready AI or something like that.

But if you want to keep it simple you will still need to nake a way for it to compare situations like
“the players health is low, and there is a weapon, some ammo, and a health pack within my radius of interest. I better pick the health pack.” you can do this by having it go through all the player state variables and seeing which one has the biggest percentage difference between what number it has and the desired number. That’s the one to chase after items for. He needs a way to know which items help which stats.

To make him punch a zombie when he gets close, then when a zombie overlaps a cylinder component (or on tick whenever zombie is in punching range), then use LookAt to set the AI pawns rotation toward the zombie and then execute your punching function that plays his animation, then use animnotify keyframes in the animation to generate a trace to test if the punch hit, or you can put collider elements on the fists and use anim notifies to turn on or off whether they are at a point where it should punch anything they overlap with.
then when the punch counts as a hit then you apply damage at location to the zombie. and the zombie has an apply damage function to decide what to do with being punched like play a dying animation

OK that is a lot of information could you possibly break down the whole picking up items thing please, sorry it’s just I’m really new to ue4 and have not done much before starting apart from python so yeah could you please try and break that down a bit more? :slight_smile:

I meant kinda new to ue4 like as in new but not but anyway could you try to break it down for me?

i probably cant explain the whole thing right now but most people implement picking up an item by actually storing a variable in an array or set to indicate that the player has the item, and destroying the item’s actor from the world. so the item actor is gone but the player says “I have the item”.
You dont put the actor itself into the array, because it will disappear from the array when you destroy it in the world. Instead you add a number or enum named after the item, or a struct or other non-actor object. Enum is probably best for you at your stage of ability and lots of pro games do it that way.

if the item is not an inventory thing and is just health or ammo or something the player always has in a certain amount, then your life just got simpler: Juat destroy the item and add to the player’s current ammo or health.
Before we go furter, how much of the basics do tou know like how to create a blueprint class, how to add to and set variables during the game, how to detect collisions and overlaps, etc?

how would I go about giving the ai an inventory because I already have an inventory for the player but I’ m wondering how to make the ai have an inventory also I know most of the basics such as creating blueprints, destroying actors, how to make an animation blueprint etc. but this is my first project that I plan to release so any help is greatly appreciated :slight_smile:

Also what about the ai shooting zombies, any idea how to do that?

I dont know if I have mentioned this but I have never worked with AI controllers before.
I have been assuming someone who knows more would speak up on the thread at some point.

That being said, it seems to me that any action you want an AI co troller to do can be implemented in exactly the same way as you do for a player controller (which it sounds like you have already done).
The difference is in how the AI gets to the point of using those actions such as shooting, or things like movement control decisons such as aiming and running etc.

The simplest thing you can do for shooting at enemies is to just have a cylinder collider around the AI pawn whih when overlapped, checks if there is a line of sight to the Other actor who entered it (could line trace to the Other and see if the actor it Hits is the one who overlapped) and if that all works out then set an Actor variable TargetEnemy to that Other who overlapped.

Again if you want to make things very simple you can have the AI only able to do one thing at a time, either search for items to pick up or ahoot at enemies, and have an Enum var to track which state he is in.

You can have a 0.25 second timer event which checks if TargetEnemy IsValid. If true then Set Control Rotation to the LookAt between The AI Pawn and the TargetEnemy.
Aso on this timer event if TargetEnemy isValid, do a Line Of Sight check (might be better than the trace node mentioned earlier for this and the overlap check) from the AI pawn to the TargetEnemy. if it fails, the enemy can not be seen so set the TargetEnemy variable to none and the mode enum var to look for items.

Come to think of it maybe we dont need a mode enum if we have a TargetEnemy since he always shoots at TargetEnemy if TargetEnemy is in line of sight and always searches for items to pick up if there is no TargetEnemy set.

For grabbing items and moving toward them you can do similarly and have a TargetItem and he just moves forward or MoveTo location as long as that is set AND TargetEnemy is NOT set.

If you want it any smarter than that or be able to weigh decisions of fight versus get item (which you will need if there is never a time when there is NOT a zombie in sight to make him free to get items) then you really need to watch some of the many free AI tutorials out there to see how they do it. In epic’s free Live Training tutorial seties on making Game Ready AI, they show how to make the AI find items and decide whether it is worth going after them or doing something else. it is a long series to watch but it probably answers ALL your questions if you need AI that can weigh priorities against each other like "I need to fight Zombies but I ALSO need to grab items. Which one is more urgent rivht now at this very moment?

Also shows how to use behavior trees and EQS queries. if you sont want to slow your game down by running tons of GetAllActors nodes every tick or slow your AI down by limiting such things to only every 0.25 seconds or so, then you should learn how to use these tools.

The approach you take that would be easiest will depend on how many zombie will
be visible and in range and how the items affect the pawn that picks them up. Maybe you can do it without learning the tools but it sounds like you want the AI to have a smartness level that requires them.

any idea which video the ai picking up objects would be because there’s 11, also thanks for all of the help so far :slight_smile:

For game ready ai.

You are asking for some pretty complicated stuff here. Creating AI anywhere close to what you are talking about is no easy task. This is definitely behavior tree level AI. I am not sure of any specific “AI pick up” videos but to be honest from reading this post it sounds like you should not think about creating “Game Ready AI” right at this point. Try creating “AI” period. Break up what you want your AI to do into small tasks and tackle those individually. Get them working properly and add to it slowly. I guarantee you by the time you figure out how to do all of the stuff you want individually you will have realized you did some things very inefficiently or you didn’t have the best method for implementing that particular behavior. Once you can get each mini function working then you can try and put the entire thing together into one smooth, efficient behavior tree for “Game Ready AI”. The reason I say this is because I know, I once needed a tutorial for everything too eventually you break away from that and are able to think logically through any problem and start figuring out your own way to find a solution. For example, if you can manage “player” inventory what is the big leap between that and “AI” inventory? You don’t need a tutorial specifically for that if you have done it for the player. You have to see that “player inventory” and “AI inventory” to the computer are basically the same thing, a collection of variables. The only difference is who “owns” those variables. For “AI” you prob don’t need a widget to “see” the inventory, but the back end would look identical to the player’s. When the “AI” overlaps a particular object you would “add” it to the inventory just like if the player grabbed the same object. The logic is the same. How you “manage” that inventory is different but again, small steps you have to work out the logic for what would cause the AI to “decide” to use say a health pack assuming they had one. Maybe it checks its own health and if < 20%

use the health pack. AI is just a set of logical rules to follow. Variables to check on and act based on those values. You already have the basics of how to create things in blueprints, you can def create the AI you want with all these features, I am just saying no one is going to be able to come here and post a link or explain to you exactly how to do everything exactly the way YOU want. You have to tackle this one mini feature at a time.

As others have said, you are asking a complex question and you can go about it in many different ways. Here is my recommendations:
-Start by creating a basic BT that has the AI follow the Player (the easiest thing to do)
-Then add your first functionality - add a sphere collision to your AI and on Begin Overlap event, check the actor for a specific tag (say “tagPickUp”). At this point you can write your logic for the AI to pick up the item.
-Continue to add more functionality like detect enemies nearby, etc.

The key is to start small and add overtime. I started learning AI this January and Im still learning. Look for tutorials on Behavior Trees, EQS, Pawn Sensing / AI Perception. Those systems all work together to get you any behavior you’d like :slight_smile:

Would you happen to know of how I can make ai search for items at all because I am 100% stuck :slight_smile: