Smart Enemy AI | (Part 11: Group Enemy Combat) | Tutorial in Unreal Engine 5 (UE5)
Вставка
- Опубліковано 19 чер 2024
- Learning Goals:
1 - Create a token system that allows you to coordinate a fight between multiple enemies at once
2 - Increase or decrease the difficulty of a fight based on the number of tokens
3 - Achieve a more predictable fight by ensuring that enemies communicate with each other before attacking (through tokens)
Note:
This token system is a simplified version of what "Doom" does to control the flow of battle and increase/decrease difficulty. You can mix this approach with a "priority score" that assign an attack priority to each enemy depending on the factors of your game (Like how close they are, or if they have a powerful attack ready) then you can mix this priority score with the token system for a more advanced approach
Link to my Patreon (Thank you for your support)
/ alizoh
Join my Discord server to chat and mingle with the community
/ discord
Link to part 1 of the "Smart Enemy AI" tutorial:
• Smart Enemy AI | (Part...
Link to the "Damage System" tutorial:
• How to Build a Combat ...
Link to the "Projectile System" tutorial:
• How to Shoot Projectil...
If you would like to support me on Patreon, you will get access to all the source code from every video I post as well as any custom assets that I create. Also I would be forever thankful to my early adopters
/ alizoh
Checkout my other tutorials on my channel:
/ @alielzoheiry
Chapters:
00:00 Outcome of This Part
02:03 Add Increase/Decrease Tokens to Damagable Actor
09:40 Set Tokens Count for Player
10:18 Enemy Checks Tokens Before Attack
14:42 Explaining What Needs to Change
16:03 Refactoring Enemy Attack Functions
29:20 Refactoring Melee Behavior Tree
38:43 Updating AI Controller to Prevent Enemies Colliding
39:46 Refactoring Ranged Behavior Tree
45:37 Final Test
47:02 Return Tokens on Death
49:15 Next Up In Part 12
About me:
I've been learning game development for a few years now, I do have a background in software engineering, and I also have a background in education, so being able to combine my love of gaming and love of education is the best way to spend my time.
I am currently working on this 3rd person action adventure game as a hobby, but I am also trying to build a community, thus I am creating UA-cam tutorials to find others who are interested in game development and design.
If you are interested in learning more or if you are interested in working together, please let me know in the comments.
#unrealengine #unrealengine5 #ue5 #gamedev #smart #enemy #combat #AI #blueprint #tutorial #behavior #tree #behaviortree #tokens #doom #group #combat #multiple #enemies #coordination - Ігри
you've earned yourself a new patron with this goldmine of information for current & future game devs, keep up the outstanding work :)
Thank you so much for your support and becoming a patron! I'm thrilled that you found the content valuable, and I'm looking forward to providing even more useful information for game devs in the future!
Love watching your tutorials, I didn't even plan to add a token system but I still watched all of this video. I still implemented the Jump Land Move to fix and changing the parent class for the AIController because I plan to have a lot of enemies to fight against at the same.
Hey, thank you for your kind words! I'm really glad to hear that you found the video useful. Best of luck with your project, and feel free to reach out if you have any more questions along the way!
This is just exactly what I needed. Thanks a lot man, keep it up!
You're most welcome! Glad you find it helpful, I'll definitely keep making more 😉
Great video Ali. Finally completely caught up.
I was about to suggest the AI teaming when I got to your outro, so I'm looking forward to next video!
Thank you! And indeed the teams part is needed for nice group combatn
Great thanks to your tutorials! Always being helpful!😃
You're welcome! Very happy that you found it helpful 🙏
Amazing content as always. Thank You! I'm always looking forward to future content, and team combat sounds like it will be a lot of fun :)
Until then. Stay Blessed 🙏
Thank you so much! I'm also really happy with the direction this is taking, I hope it continues to be useful 🙏
Thanks bro for this ! I am working on my RPG PROJECT as a Indie Developer! Which consists of different clans that's why I needed this tutorial to make fight between player and the other clan members on their ability!
Awesome! Glad I could help 🙏
But what an incredible video, the relevance of the tutorial, the pedagogy, the patience, the quality, each video is an appointment not to be missed.
I'm really happy, because this kind of mechanics is really useful honestly, it helps me significantly for my project, and especially to understand!
It's so satisfying to see your AI evolve, to see it jump, to see it group attack, it's really gratifying haha!
Thanks Ali, thanks for your videos!
Thank you so much Shizuma, as always, your support means a lot to me 🙏😊
@@AliElZoheiry so instead of using this token system we can do like each enemy to have certain amount of time untill next attack (2-3-4-5 sec) in the BT so then enemys attacking same time or random right? what will be the diffrence betwin this and that case?
@@MaxStudioCG2023Hey, so we do we use both a cooldown on the enemy attacks as well as this token system, it's not one or the other, because they both work together, when the enemy cooldown (or timer) is up, then they check if they can attack or not (based on the token system) and if not then they wait and check again later
@@AliElZoheiry yes but can work without this token system too ....im saying we can just use the cooldown without this token system and works kinda the same (for example 1enemy have cooldown 2sec and other 5second ...or 2other enemy same cooldown and kinda will work the same as the token system i think coz then they attacking random or both same time ) .....
@@MaxStudioCG2023 it will be a very rigid system that doesn't scale with the number of enemies, or number of attacks or different cooldowns, it will cause a lot of timing problems, and multiple enemies could be on cooldown at the same time, then no one is attacking, so it's really not scalable and advise not doing that 😅
Great. Thanks again for a truly magnificent tutorial.
My pleasure, and thank you for the support as always 😉
This is the tutorial I expected for make my beatem up, thx.
You're welcome! I hope it helps 🙏
Very well explained, like always🙌
Thank you for the support as always 🙏🙏
(new google account, old one was nightmare or smth)
I've been moving onto my own projects so im still stuck on number six, but this is an incredible series. it helped me get off the ground for a ton of recreations of games, and gave me the courage to attempt to remake the fnaf one entire game. thank you so much for these videos, we love it.
I'm very happy to hear that. Glad that this is helping you, and thank you for watching as always ;)
10/10 perfect tutorial as always
Thank you so much 🙏
Quite an interesting idea with using tokens for the AI to use. I like it.
Thank you! I can't take credit for the idea though, I read it in a dev log from "ID software" (the developers of Doom), so I tried to create something based on that
Do you still have that devlog link? I’d like to know more about the system.
@@viniguerrero I believe it was this one ua-cam.com/video/RcOdtwioEfI/v-deo.htmlsi=eBPglxzouXJYaHZ3
Thanks a lot @@AliElZoheiry ! This is quite an interesting subject
😂😂YESSIR this was exactly what i needed thanks again for this Ali
My pleasure! Glad you found it helpful 🙏
Terrific tutorial as always and im loving it so far. Saw it mentioned previously but I also notice the Ai controller as detour breaking the navlink proxy. seems the colliding with the edge of the surface they want to jump up to causes them to just jump up and down continuously. 5.3 as well. Likely a bug but thought I would mention it anyway.
Hey there, thank you for watching and commenting, really glad you're finding this useful. Regarding the navlink and AI controller. There is indeed a bug with v5.3+ with the detour crown controller, I haven't used 5.3 myself, but I heard that from a lot of people. So if you're on v5.3, I suggest using the regular AI controller parent
Dude, do you know how long I was stuck tring to get my enemies to not block each other?! You are a life saver!!
So glad to hear that I could help you out! Happy to be a life saver 😉
yesssss!!!! at last! hehehe many many Thanks
You're very welcome! Hope you enjoy it 🙏
Thanks crazy Tutorials that u make with them i can make a good ai system PVPVE game Thanks thanks thanks!!!!! juuuhuuuuu 😄
I must support this!!!
You're very welcome 🙏 and thank you for the support, I really appreciate it
amazing!
Thanks! Glad you enjoyed it 🙏
@@AliElZoheiry thank you!!!!!! i havent even refined the ai and it already beats some mainstream games, im used to playing skyrim and this is already a big leap, rdr2 is very realistic but the ai is pretty simplistic also. when it comes to combat i mean
Hi, Ali! Just wanted to say that you content is amazing. Did you know that in functions instead of pulling from inputs you could just type get "variable name" so blueprints will be cleaner?
Hey there! Thank you for your kind words, I did indeed know that, but often I avoid it because then I have to read the full function to see where the variable is used, whereas if I use it from the input pin on the function name, I can easily track where each input has been used, but definitely useful when you have to use the same variable multiple times in different places. I appreciate your support and I'm glad you're enjoying the content!
Such good tutorials, I wish there were more C++ based ones of this quality...
Thanks for your kind words! I'm glad you're enjoying the tutorials. I'll definitely consider creating more C++ based tutorials of similar quality. Thank you for the suggestion and your support!
Again a great tutorial Ali! When the AI dies how do you have them unequip their weapon so you don't end up with lots of weapon geometry end up in the env when they die?
Hey there, glad you enjoyed the tutorial! I haven't really covered death properly in this series, but generally speaking, you should either remove the entire actor after a while to free up some memory and not render unneeded actors. Or if you want to keep the mesh, then you should indeed consider what to clean up to make the game as performant as possible
很赞,加油
Thank you 🙏😊
Hi Ali, thank you very much for your work and for sharing your knowledge. Do you think it is possibile to explain us a cover system for both player and enemy? Not something that works with tokens that you have to manually place all around the map, though. That kind of cover system is very time consuming. Thanks in advance
Hey Giovanni, you're most welcome 😁 I briefly explained how to get an enemy to hide or take cover where the player can't see them (to go heal) in this video here ua-cam.com/video/18Awm1RYNMk/v-deo.html but I'm not sure if that's what you're looking for
Bro is high af 7:16 but still pulls of one of the most useful vids
Hahah, glad you found it useful! Thank you for watching and commenting 🙏
Еще раз Большое Спасибо!
Конечно, не за что! Я рад, что вам было полезно!
Love the series! Just posting as FYI (in case anyone else has similar issues)... When you switch the parent class of the AIC from "AIController" to the Detour AI Crowd Controller, enemies stop using the Nav jumps properly. They just jump straight up, in place. When I switched the parent class back to "AIController", they jump forward as they did before. Not sure if this is a bug (currently on v5.3) or if this is something that is addressed in a future video.
Hey Kyle, thank you for your comment. I haven't tried this in 5.3, but in 5.2 it works well
Im on 5.3 and this is also an issue for me. Must be something that changed with the system
im also having this issue in 5.3
Same. I’m trying to fix it.
AWESOME🎉🎉🎉🎉🎉🎉🎉
Esto es otro nivel apenas y sigo el ritmo 🥲
This is another level barely and I keep up 🥲
I'm glad they're helping you 😊
Hello! Late on this series but amazing course so far, i'm new to Unreal coming from Unity :)
I noticed an issue, when refactoring parent class to DetourCrowd the enemies are not jumping correctly anymore (they jump on place), i believe they're trying to avoid every collision so they don't want to get on platforms and drift back
Hey there! Thank you for your comment, and I'm glad to hear you're enjoying the course so far! That's a weird bug. I haven't encountered that before to be honest.
@@AliElZoheiry Hello Ali, thanks for this AiSerie, I have the exact same problem here,my enemy is jumping in place.
So, which Doom uses the token system? Is this from the original Doom or is this system used in Doom 2016?
This video explains the token system in Doom 2016 ua-cam.com/video/RcOdtwioEfI/v-deo.html but it's also possible that it was used in the original one as well.
I love your teaching style and the tutorials are amazing btw. Im having an issue with this one, my melee enemy changes the values of the tokens, somehow taking more and more away or adding more and more tokens.
Thank you BooneyianLogic, glad you're liking the tutorials.
Here are some things to check to debug your issue:
- If you are setting the TokenCount of an attack to "0", make sure that the variable called "TokensUsedInCurrentAttack" has a default value of "0" as well (this is in the base enemy class)
- Make sure you are calling AttackStart & AttackEnd on every attack, and that they are not interrupted in the middle
- Add breakpoints in your attack functions to trace the execution flow to see where it goes wrong.
Hope this helps.
thank you very much for the reply. i will look into breakpointing the token system to ensure it works, i still dont know what i did to my jump function, when they jump they seem to not move in any direction except upwards, in both the sword jump attack and the navlink jumps.@@AliElZoheiry
🎉🎉❤❤
Thanks for the tutorial on this! For some reason when I implement it into my setup (Just the token getting and returning section), it works successfully until I start to kill enemies then I always end up being stuck with 0 tokens to give. Any idea as to why this could be? Been trying to troubleshoot it with no luck.
Of course as always after asking a question I figure it out. I wasn't deleting the actor and wasn't setting to stop trying to attack after dying, so it would still reserve the tokens. It wasn't a noticeable issue before as the enemy was just dead on the ground visually.
Awesome! Glad you found the issue 😉
Which version are you using ?
V5.2
This methods also improves profromance compared to all the attack all at ones ?
Doesn't really have an impact on performance compared to without this system
Good work brother will you make tutorial about block the gun attack with sword
Thank you 🙏 and I already made a tutorial on blocking gun attack with the sword in this video ua-cam.com/video/84upuVN6s1Y/v-deo.html but I will be improving it and fixing some bugs in a later video
@@AliElZoheiry wow you are the best thank you
@haythembenhaddada9988 I just wanted to give you a heads up that I will be improving the block gun attack behavior in my next video, so it will build upon the video that I shared with you in the comment above, but I will make some improvements to it, in the next video (Part 12)
@@AliElZoheiry thank you brother your videos are amazing and very helpfull god bless you
interesting tutorial, I'll keep it for my work.
is it possible to make a series not with a default mannequin and animation blueprint?
I would like to use it, but I have my own, non-standard models and skeletons for them.
thanks.
Hey Dina, I'm using the default Mannequin because what applies to the Mannequin can apply to any other character, it won't really make much of a difference if you use your own characters, especially since I'm using custom animations as well
@@AliElZoheiry Unfortunately, I don't understand the engine well enough yet, but thank you. I will try to combine this tutorial series with some other one where it is described.
Another question, can you make a tutorial on the possibility for AI after he runs up to the player character to attack, walk around this character trying to get behind him?
Well I have shown the strafe functionality and how to use the EQS to get the enemy to position themselves around the player in a specific way in this tutorial ua-cam.com/video/Oy_LojjRiWo/v-deo.htmlsi=XjA6Rz6dkWrROnLv So using the same concepts you can get the enemy to move behind the player
@@AliElZoheiry thx
I'm using v4.26 and I can't find the "Delay until next tick" node. Was it added in unreal version 5?
Not sure when this node was introduced, but doing a regular delay with a very small number does the same, I think even a delay with zero will still wait till the next tick to trigger
Hello, could you please guide me where you found info about how Doom designer theirs bots?
Of course, This video explains the token system in Doom 2016 ua-cam.com/video/RcOdtwioEfI/v-deo.html
Hey Ali, thanks a lot for this tutorial series. Perhaps you could show how enemies can surround the player, attacking him from all sides, for example (attack formation) In my solution I used EQs to create a point circle around the player and then the ai would walk to a point if it isn’t occupied by another ai. It sort of works, but I have the feeling that I hacked the code together and my solution isn’t very smart. Perhaps a topic for another ai tutorial?
You're very welcome, glad you like it so far.
Thank you for the suggestion, it's a pretty interesting topic, and I think your solution is not bad. I would tackle it in a similar way.
If you want to try different solutions to see which one is better you can try a few of these
- instead of checking if a point is occupied by an enemy, you can already generate a point Infront of the other enemy but behind the player. Then if every enemy does that, it ensures that they stand in a circle around the player.
- or you can have each enemy reserve a certain angle around the player, and store that value somewhere, then each new enemy that comes takes up another piece of the circle, ensuring they never overlap
Hey man i have this problem where when my Player respawns after death, when i killed an enemy, then when quiting the PIE it shows "Blueprint Runtime Error: "Attempted to access Player_C_0 via property K2Node_DynamicCast_AsBPI_Damagable, but Player_C_0 is not valid (pending kill or garbage)". Node: Return Attack Token Graph: EventGraph Function: Execute Ubergraph BP Enemy Robot Base Blueprint: BP_Enemy_Robot_Base"
Robot base is my enemy base, and player is my base player, idk why it keeps pooping that whenever i respawn and then kill enemies, it doesnt happen if the player doesnt die
Hey there, that's nothing to worry about, this probably means that you have a timer running somewhere trying to access the player after they have been removed from the level. If it doesn't happen often, then it won't cause any performance issues. If it does happen often, you can just add a branch and check if the player (or whichever actor is giving the error) "Is Valid" before accessing it, and only on "true" do you access it
This time it's like a Dark souls enemies! AND I AM RIGHT NOW MAKING Dark Souls like a game! I am really so grateful for you.
You cool guy
Awesome!! Really happy that it came at the right time for you 😊
@@AliElZoheiry really I can't wait to see next part's. You very awesome person
I am really so gladly meeting you
@@AliElZoheiry I am really so sorry for disturbing you. How much part's will be there?
Hey Roy, no disturbance at all ;) But I haven't decided how many parts yet, I will just keep going until I run out of ideas, or if I find a different series that is more interesting
@@AliElZoheiry You awesome person! Thank you so much! I am really so gladly meeting you.
I am gladly helping supported you ❤️
Now my melee enemy only strafes when I uncheck the inverse condition on the “is within ideal range node” also only attacks once and then stands near player. Lastly, they won’t run to the player when they start strafing and I run away, remember, the condition has to be inversed for them to strafe at all. It’s weird.
1. Melee Enemy Only Strafes When Inverse Condition is Unchecked:
- Make sure that the conditions and logic in your behavior trees and blueprints are correctly set up to trigger strafing behavior based on the distance between the enemy and the player.
- Double-check the settings in the "is within ideal range node" and the associated conditions to ensure that it triggers strafing as intended. You may need to adjust the conditions or distances for proper behavior.
2. Melee Enemy Only Attacks Once and Then Stands Near Player:
- Check the attack logic in your behavior tree and blueprints to ensure that the attack behavior is properly triggered and looped.
- Verify that there are no unintended pauses or stops in the attack sequence that could lead to the enemy standing near the player after a single attack.
3. Melee Enemy Won't Run to Player When Strafing and Player Runs Away:
- Review the movement settings and conditions in your AI controller and behavior tree to ensure that the enemy can smoothly transition from strafing to chasing the player.
- Adjust the AI behavior to prioritize chasing the player when the player moves away, even during strafing behavior, by updating the movement logic and conditions.
I have deployed four melee enemies, but only one of them considers the player as an enemy. The other three recognize the enemy that targets the player as their enemy. Where might I have gone wrong? I'm not sure where to start debugging.
After trying various tests and almost giving up, I decided to revert to the old method of creating the attack using nodes. I checked it and then switched back to the refactored task to see the previous situation again. Surprisingly, now all the enemies take turns attacking as intended. It's quite amazing...
In the part where you handleSensedSight, this is where we setup what happens when enemies see each other. If you followed the next tutorial (on setting up teams), then you should have a condition there in that function that checks if the actor sensed is on the same team or not, and if not, it will attack them. So double check that part and make sure you didn't miss anything
Wow pls make ai random spawn system too.
Hey! Thank you for the suggestion, I'll add it to the list 😉
Can i use this ai series for a mmo rpg game?
Please answer
]
The behavior can be used in any type of game, so of course you can use it for an RPG game, but if you want to make an online/multiplayer game, then you will need to add "replication" to this AI behavior, because I've only shown how to do it for single player games
@AliElZoheiry thanks I will watch the whole series cuz you are helping a lot for learning the engine
So, if you can only ever damage one Target at a time, what is the point in having a dictionary at all? since when you call Attack end, Attack start you only deal with one Attack target at a time, when you call "Death" you will also have at the most one Attack target in the dictionary, but since you remove the tokens on interrupt too, I don't think you have any tokens to return there either.
Hey there! Keep in mind that every attacker can have a single attack target, but the attack target can be attacked by multiple attackers, so it's a one to many relationship, and that's the reason for having the dictionary
I'm implementing a simpler system, but I just wasn't able to understand the logic behind having a dictionary for it, maybe if you can damage multiple characters at the same time or attack.
So, are you stupid or don't care to reply?@@AliElZoheiry
I tried following the video exactly as was taught. My melee enemy are working fine but Ranged enemy just doesnot move at all. It keeps on shooting projectiles from one place standing idle. When I run away it doesnot follow me at all. Is anyone else facing similar issue.
Hey, not really sure what your problem is, but make sure the ranged enemy is running the EQS correctly, and their movement speed is not set to zero, and that they are not already standing on the ideal location
I am interested in being your petreon member, do you have un-released video there?
Hey! I don't have unreleased videos there but I upload the entire project files on my Patreon free to download and use in your own games www.patreon.com/Alizoh
@@AliElZoheiry you are an awesome human being :) 👍
My enemies dont attack now :( they just circle around me strafing, and i have plugged in AI move to the Controlled Pawn you missed in the end also.
This is in the BTT_MeleeAttack
Sounds like you're token count might be zero, try debugging and seeing if there are tokens or where the behavior stops
I had the same problem. Did you fix it?
sir how can i fix my melee enemy is trying to walk through walls
so let me explain it i tryied to debug it but i found that in seek subtree its stuck in move to point of intrest and when i run away and take that turn on the slope it just walk foward then switich states so rapidly in trying to move to ideal range to attack i guess its just tweaking and doing wired stuff like walking through walls whenever i am getting move to or move to ideal range node and specially these two places like when attack range and while seeking
Hey Akib, I'm not really sure why that would happen, to be honest I don't understand the problem quite well without seeing it
@@AliElZoheiry it's okay the wall problem was fixed when I created one more new level seems like it was glitch but I tested the melee enemy it's just losing head like not changing the movement speed and all those stuff
the enemies hit each other and the player also.what i do wrong?
Hey there, Unfortunately I can't help with more info 😅 I suggest asking your question on the discord community, or look for a similar question asked, maybe someone already faced this problem. Good luck
Hi there! Are you able to make a tutorial about the player being able to target the clostest enemy to it?
Hello, That kind of functionality is going to be more related to a player combat system and not really related to enemy AI, so I will consider it once I finish this AI series though
@@AliElZoheiry Alright that’s fair enough! Any suggestions on how to go about it as I could probably code it myself. But I’m not sure if I should check the distance of enemies to the player or who the player is looking at. I’m just not 100% on how to go about it. Thanks
@@mrknowbody_if you already have a targeting system implemented, then the rest is quite easy. To get the distance between all enemies, use "get all actors of class" node to get all enemy actors. Then loop over them, and use the "get distance" node to get the distance between each enemy and player. Then the closest one is your target
@@AliElZoheiry that makes a lot of sense I’ll implement soon! Thanks
@@AliElZoheiry Sorry for all of the questions but... how would i go about making the enemy not attack the player if they're reacting. I've tried to setup a blackboard condition on the attack however i don't think it works. Thanks in advance!
now one more new problem is that my melee enemy is strafing faster even when i used the setmovementspeed correctly like what the first problem was solved by changing the map but this one is just frustrating
Is he actually moving faster, or just the animation playing fast?
@@AliElZoheiry no aniamtions were good but the speed functions in melee enemy was deleted i dont know i didnt touched that after i made it properly its randomly got missing i put the ranged enemy and melee toghater to see the difference between them then i got to know about it its fixed just today i catch up with this toturial but that he trying to walk thru walls like jin is wired i had to create new map then it waas fixed i dont know why it happend si there any option that controls ai path on maps
actually i reliased it is not stoping on higher platforms its just jumping down and thhen coming to attack i deleted the nav link
and i just find out that every enemy behaving like that
\
can you add budyy AI tutorial?
That's a great suggestion, I'm currently focused on enemy AI, but I'll definitely consider a friendly AI as well
>not coordinated in any way
they are too coordinated and all attack at the same time.
That's one way to look at coordination 😅
system is not working
Sorry to hear that, I made a video on how to fix bugs, it's on my channel. Maybe it will help you find the issue you have
@@AliElZoheiry thanks for your reply , the problem was in the new 5.3 update in the ai tree the actor location was not updating it so enemy just stuck in same postion sorry for that .greate video ,keep making these kind of video ,it really helps me 🫂
@@user-zj7oq7zz2rhow did you fix it?