#Beginner approach to making AI
1 messages · Page 1 of 1 (latest)
Hard to give a generic answer here, it depends heavily on what your AI is supposed to do. Let's say you have 2 distinct modes of behaviour: roaming around and pursuing the player. Let's also say that touching the player damages them.
- Add a Brain node that decides which state the AI should be in. At first, it is always in the roaming state.
- Add the roaming state as a child node. It randomly moves the character around.
- Add an area2d as a child of the character with a circular collision shape. When the player enters this area, the AI aggros.
- Hook the signals up to the brain so it can change the state to pursuit when the player enters and back to roaming when it exits the area.
- Add the pursuit state. Start simple, just move the AI towards the player so it can hit them on touch. You can then improve this setup by using a navigation agent (check out docs), so the AI can avoid obstacles.
I left out a lot of details, but this is how simple AI works: The brain decides WHAT to do depending on game state and detection and then delegates to the desired system that know HOW to do it.
By Brain node, I'm guessing you mean a Node2D or something similar with the script?
Yes, a simple Node would be enough.