+2 votes

Need some advice on AI. Plan is to have them move around until they spot the player. Once spotted attack and move to the player.

Currently my enemies in game are KinematicBody2D. Would it be better to make them under a navigation 2D to use GODOTs navigation nodes to move them around? I don't have a lot of experience with AI so any advice would be great!

in Engine by (39 points)

1 Answer

+6 votes
Best answer

There is no best way because "AI" is a too broad subject.

So far i've been doing simple AIs, they were almost always based on a state machine idea in mind.
I had a script with a state variable, then I execute a different _process function based on that state. In any given state, if some condition is met (player seen, player escaped, took damage...) I change the state variable to go to another behavior in reaction to what happened, so the AI can start running after the player, escape, or go back to patrolling.

There are more complex ways to do AI such as behaviour trees, genetic, and algorithms such as pathfinding are often useful when implementing them (Godot has pathfinding utilities for that, like Navigation2D as you said, or the AStar class).

by (28,884 points)
selected by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.