[blueprint]Making an AI attack another AI on sight.

how would one go about making 2 different ai characters attack each other?
have experimented a little with it, and downloaded a community AI template. 6f4bba275799184fef90ea01068807bf18a10e06.jpeg

so can someone else please explain to what defines the target it will attack on sight? becouse clearly i dont get this piece of code.

bump, no one knows :)? or have i formulated my question wrong?

I actually set something up like this last night, I have Archers firing at enemy’s (called MongerDaves ;p). I also used GetAllActorsOfClass here’s how how they acquire a target and then call the FireArrow event at a random enemy:

i see, in the GetAllActorsOfClass, what part of your MongerDaves did you set? was it the mesh blueprint? or what?
im still in the steep learning curve ^^

It’s not such a simple question and needs to be broken down into lots of incremental steps. Those steps could vary from project to project, but here’s a rough outline.

-Who is my target?
-Where is my target?
-Can I see my target?
-Can I attack my target from where I currently am or do I need to move to where they are?

  • Attack Target!

Now each of those needs to be broken down further. Alot of the logic here would be controlled via a Behaviour Tree, which would then fire information out to other Blueprints to handle things like animation.

I would recommend starting by going through Epic’s Behaviour Tree guide here:

And Peter Newton’s 5 part AI tutorial here:

Creating AI in UE4 means getting comfortable with alot of types of Blueprints and cross references each other. It would be better to get to know how to do that via those tutorials than to just rely on the community provided AI alone without understanding how it works.

As for the actual attack, what kind of attack are you talking about- ranged, melee, area etc? At the very least you would need to set up a health system, track that, change that and then kill a characte off when they die.

ahaa. that surely makes sence. i have watched newtons guide wich gave me some insight towards it.
but then again, as refered to at the top, i downloaded newtons AIproject template wich has those features. what i dont understand still lies in the GetAllActorsOfClass node. where if i put MyCharacter[the player character] the bot works perfectly, but if i change ‘‘MyCharacter’’ to a simple blueman copy named ‘‘Zombie’’ and then place ‘‘Zombie’’ in the bots path it just ignores it?

so there must be something i’ve missed since ‘‘zombie’’ doesnt invoke the same spot->run into range->attack as it doesnt with ‘‘MyCharacter’’

Try adding a ‘Print String’ in the ForEachLoopWithBreak to see what value is being returned. That way you can tell if a zombie is being seen but ignored or not seen at all.

[EDIT] You’ll need to get the actor name off of the Array Element output in the ForEachLoopWithBreak node :slight_smile:

so i’ve played a little bit more with it, does the character pawn need the AIcontroller to have a ‘GetControlledPawn’ in order to see the pawn as a acceptable actor?

or just generally having a minimum aicontroller setup to control the pawn

What i have done myself with great success:
1- Add a PawnSensingComponent to your bot pawn, this will give you a SeePawn event for blueprint, use that to set the target to attack.
2- Also, of course the victim should attack back, so add that the other AI attacks the one who attacks him, so set the enemy using the instigator from TakeDamage event.
This simple thing is working just fine for now in actual serious games, for an AI im developing for the game Heavy Gear Assault, i also use the pawnsensing component to get noise and target that.
Once i set the enemy on someone, that fires the whole behavior tree logic i have for combat stance.

And the problem is solved. everything solved itself when i recreated the ‘‘zombie’’ charactors setup with some of the pointers you guys gave me :slight_smile:
never the less, a thousand thanks to you guys for your most helpfull advice and bonus idea’s to how it can be done with greater results! :slight_smile:

AI is wierd to begin with, but the pieces are slowly falling together

I have same question with you, how you solved it? could you please give me some tutorial and pics?