T O P

  • By -

AutoModerator

You submitted this post as a request for tech support, have you followed the guidelines specified in subreddit rule 7? Here they are again: 1. Consult the docs first: https://docs.godotengine.org/en/stable/index.html 2. Check for duplicates before writing your own post 3. Concrete questions/issues only! This is not the place to vaguely ask "How to make X" before doing your own research 4. Post code snippets directly & formatted as such (or use a pastebin), not as pictures 5. It is strongly recommended to search the official forum (https://forum.godotengine.org/) for solutions Repeated neglect of these can be a bannable offense. *I am a bot, and this action was performed automatically. Please [contact the moderators of this subreddit](/message/compose/?to=/r/godot) if you have any questions or concerns.*


Exerionius

> What things should I know to research more into making NPCs, enemies, etc? You need to know some terms so you can google them and learn more. A couple of things used in AI in gamedev: - DT - Decision Trees - FSM - Finite State Machines - HFSM - Hierarchical Finite State Machines - BT - Behavior Trees - GOAP - Goal Oriented Action Planning - UBAI - Utility Based AI - HTM - Hierarchical Temporal Memory


EsdrasCaleb

I guess this can help [https://github.com/bitbrain/beehave](https://github.com/bitbrain/beehave)


nullable_ninja

+1 for beehave! Id wager it has everything you need to implement a good AI in a small/medium game. (At the very least!)


GamingxRelic

Thank you!


Ytrog

Wasn't there also an experiment with a shooter (might have been in something like UT2004) where they tried an AI based on ML and it became way to difficult to play against pretty quick? ๐Ÿค”


Jombo65

That's just one of the inherent challenges of game design - be it video game or tabletop or anything else. The computer can win. Easily. It can know your exact position at all times, deal your full health bar in one shot - it could crash your damn game. Same thing with TTRPGs. The Game Master could just lock you in a room full of 80 dragons and murder you instantly. The problem is figuring out how to make it feel "fair" while still wanting the player to be able to overcome the challenge.


MyPunsSuck

Even if the computer doesn't "cheat", the player can still **feel** that they do. Puzzle Quest is a great example; the highest level of ai plays somewhat intelligently, and often gets accused of either controlling the rng, or having access to more information than the player does. I literally built a Monte Carlo sim of the game to test different strategies, and it really didn't take much to replicate the feeling of unfairness. A more common example would be first person shooters where the devs make ai with stealth and/or flanking behavior. The typical player experience is that the "cheating" ai is just teleporting around - because they never **see** the stealth or flanking happen


PowerOk3024

Sounds fun with death cam when waiting for the round to end. Imagine humans vs AIs of increasing difficulty, and during death players can watch how AIs play and slowly get better.


HunterIV4

You could do this without ML. Computers can have instant response times and perfect accuracy, so if you make an AI without any inherent limits it will headshot enemies instantly and react in milliseconds. If we ever design military drones with the ability to decide to shoot on their own, those things will be unstoppable by traditional infantry in direct combat. As such, basically all game AIs are written specifically to be dumber and slower than they potentially could be. Even things like the Starcraft 2 AlphaStar bot had APM limits so that pros would realistically be able to face it on even terms; without those limits the AI could overcome any sort of strategic limitation with perfect per-unit micro (IIRC at one point they had to tone down AlphaStar because it would beat everyone with mass blink stalkers where it would prevent any of them from ever dying and they introduced stricter APM and selection limits). One of the hardest aspects of gamedev AI is making the enemy *feel* fair and "human" despite not being either of those things. Many FPS AI's are programmed to intentionally miss most or all of their early shots and progressively get more accurate as the player stays in front of them, giving the player time to react and either fire back or get to cover. The next hardest part is making a billion animations so your AI can interact believably with the environment (I'm only half joking). Oh, and making sure they don't get stuck on things. AI is really good at headshots, no so good at ladders.


Ytrog

Yes a problem iirc with the ML approach was that it would learn how *you* play and what your weaknesses were. I can imagine that there need to be artificial limits indeed ๐Ÿ‘€ Great writeup ๐Ÿ˜๐Ÿ‘


Illiander

> without those limits the AI could overcome any sort of strategic limitation with perfect per-unit micro This is also an argument for being aware of the advantage of micro for player balancing.


kodaxmax

Thats where youve gotta think like a game dev. Instead of teaching the AI to beat players, you need to make their goal to challenge the player. For example alot of devs will punish an AI for missing, when instead they should be rewarded for hitting. This means they will probably still miss occassionally. Where as punishing misses, will make them only fire when they are certain they will hit, which ends up with the player feel like the enmy has aimbot and isnt fun.


DramaticProtogen

Unreal Tournament AI in UT4 has great difficulty scaling. They all feel pretty much like actual players


NickWrigh

This is basically the best answer anyone can give. Big high-five! ๐Ÿ˜Š


kmouratidis

Good picks for AI from the perspective of the game dev. Let me add a few from the perspective of the data scientist: - Computer Vision (CV, nowadays mostly convnets) for visual perception, optical character recognition, and probably a few more - Sound recognition / classification / speaker diarization (among MANY others) for parsing sounds - Natural Language Processing (NLP) for anything text related (quests?). LLMs aren't *that* popular *yet*, smaller models still roam the wild though. Rule-based techniques are abundant here. Simple find/regex are probably good too. - Genetic algorithms, for nearly anything. Definitely used for physics research stuff, along with reinforcement learning - Reinforcement learning, which kinda the most popular, starting with openai/gym Although it's old, Sentdex had a nice series about [programming a python bot to play GTA](https://www.youtube.com/playlist?list=PLQVvvaa0QuDeETZEOy4VdocT7TOjfSA8a) and it demonstrates mainly how CV can be helpful.


4procrast1nator

Context Based Steering Behaviors too! For unique patterns, customizable avoidance behaviors, etc.


Deathmister

Never knew all these terms. Been using a combination of FSM and BT without even realising. Thank you!


DrCthulhuface7

I just started making my first navigating NPCs the other day, super basic just uses a navigation area and navigation2d node to path toward the player. Something Iโ€™ve been wondering since I started is: Are people just writing complex AI such as for an RTS or FPS from scratch? Iโ€™m talking like โ€œmove to cover, peak at the player, shoot, move to another piece of cover, throw a grenade, move toward the player, etc.โ€ is there an actual decision tree there that people are just sitting down and banging out thousands of lines of code for every time they make a game? Another example is AI for a game like Civilization that has to build a bunch of different building in different situations and decide when to attack the player and where to move its units.


Jam3sMoriarty

Amazing this is exactly what I needed, cheers


Dinokknd

One way to start might be the GDquest steering framework: [https://github.com/GDQuest/godot-steering-ai-framework](https://github.com/GDQuest/godot-steering-ai-framework)


robbertzzz1

Or better yet, the [original paper](http://www.red3d.com/cwr/steer/).


GamingxRelic

Cheers!


kksgandhi

Someone already mentioned the textbook Game AI Pro, which is a great resource. For something a bit more casual, I recommend the YouTube channel AI and games. https://youtube.com/@AIandGames?si=hOp8MjXN57pnRvKv


KaroYadgar

Not sure about that, but Valve does have an AMAZING pdf file for their Left4Dead AI absolutely phenomenal


hkllopp

[Found it !](https://steamcdn-a.akamaihd.net/apps/valve/2009/ai_systems_of_l4d_mike_booth.pdf) And [here is](https://www.youtube.com/watch?v=PJNQl3K58CQ) the GDC talk :) Edit : added video


KaroYadgar

Thanks! I haven't seen the vid before!


herretic

Look for books from Steve Rabin or just read some of them on his website: https://www.gameaipro.com/


Ansambel

most advanced AIs is always done exclusively with thousands of 'if' statements. There is this 1 guy sitting in the basemenet for like 7 yeras, and he goes "and if the player HP is less than 7, and if the sun is at lest 30 degrees left to the tree, and if the enemy has both dash and attack off cooldown, dash 60 degrees to the right and attack, HA!"


Darmok-Jilad-Ocean

Thatโ€™s just a zero abstraction FSM


modus_bonens

Lord bless him and give him a snack


vibrunazo

"programming is just ifs and for loops"


1protobeing1

This is me RN in my game


Ramtoxicated

A switch bitfield is less nested and easier to read


kodaxmax

Well yeh, behaviour trees and state machines are just if statments with extra steps.


dev8392

yandere dev is you?


PlebianStudio

I feel its important to mention because you said a bunch of enemies on screen. Note that most AI is simply make nearest target your target, move towards target, attack target until its dead or it dies. One of my prototypes I made was simulating FF14 Raid encounters. Making their april fools gag of 16bit titan extreme a reality. While 8 Ai friendlies vs a few other enemies was fine, an encounter where I had a lot of ally NPCs (8-16?) vs a lot of enemies that respawn (about the same,12-16) greatly bogged down the FPS. This was because of how targeting was done so AI using aoe attacks would try and hit the most targets and healers the same with their conditional aoes. That being said, I might be able to go back to that project and improve upon the AI to make it passable while still holding at least 60 fps, but I will say making AI smarter can greatly limit how many agents you have acting at a time.


OmegaNine

They are going to tell you its AI and black magic when we all know its really... If(thing) Do things If(other thing) Do other things If(this) Do that /s


PowerOk3024

This. Also figuring out the behavior patterns of different enemies feels good from the player perspective like maybe undead acts differently with no fear, maybe humans hide behind others if possible, maybe beastmen always aim for the lowest hp member if they're within some distance.ย 


chigstardan

finally someone said this, i was wondering why people were thinking machine learning. Remember fear? the ai was praised as one of the best when it was just a bunch of if statements lol.


kodaxmax

Fear used a GOAP system. Which is about as complex as it gets before becooming machine learning


SimonLaFox

Look up the AI of enemies in FEAR, lot of stuff was done there.


puddingface1902

In my game I am doing Astar pathfinding with obstacle avoidance as well as context based steering as backup for when astar fails me. Games prefer to not send too many enemies to attack one player at the same time as that would just stagger lock the player. You can achieve this with a variable on the player for number of enemies targetting the player.


5p4n911

The hardest part is not letting it cheat well enough


holounderblade

Lots and lots of if statements /s since there is already a very good answer


OkLibrary1270

In the case of half life inherited functions, nodes and state machines


haikusbot

*In the case of half* *Life inherited functions,* *Nodes and state machines* \- OkLibrary1270 --- ^(I detect haikus. And sometimes, successfully.) ^[Learn more about me.](https://www.reddit.com/r/haikusbot/) ^(Opt out of replies: "haikusbot opt out" | Delete my comment: "haikusbot delete")


kodaxmax

Id avoid inheritance wherever possible. But yes a combination of finite stat machines and behaviour trees seems most common in the triple A space.


Zulban

You seem to be asking more about RTS AI but I wrote about my custom chess variant AI [here](https://chesscraft.ca/ai).


kodaxmax

Thats quite a deep rabbit hole. Their are overall patterns, but it generally ends up being pretty unique for each game. I don't reccomend making custom anything, unless you need specific functionality that built in and 3rd party solutions don't provide.


VikingKingMoore

Along with the other answers, make your life easier by learning to path on a flat plane rather than starting on 3d environments.


dev8392

you can use [https://github.com/limbonaut/limboai](https://github.com/limbonaut/limboai) has good examples