+1 vote

I am very new using godot, it is the first engine that I am dedicating time to. I am currently working on my first game, which is a simple stealth game. I have my player, but now I need to program the enemy. I know that I need to make a finite state machine, so that the enemy can patrol, chase the player, attack him and return to patrol. The problem is that the tutorials that I find are a bit vague and do not explain 100% the steps that must be carried out, from the enemy script, to the states and the respective machine, could someone help me with that? considering I'm very new to this. Sorry for the bad English.

Godot version latest
in Engine by (13 points)

your question is too broad

Hey, since you mentioned you're a beginner, I would recommend you not getting too deep into academical stuff for now, all those fancy computer science patterns can cause more harm than benefit if used without enough confidence.
Think about it this way: a state machine - is a mechanism where you have some state variable, usually an enum, with values like: idle, patrol, attack, etc. And some logic of how these states change from one to another, like:
if (state == EnemyState.patrol) && playerDetected { state = EnemyState.attack }
Maybe one important thing to mention here is that e.g. stopAttack - is a bad example of state, because it's basically not a state, but a momentary action, so you should avoid defining states like that.
The exact implementation of this logic, as well as its complexity, is up to you. You don't need any rules from smart articles to restrict you from defining your state machine the way you want.
And after successfully implementing your own state machine you will have enough experience to start looking at those articles and see which fancy ideas you could borrow from them to make your code even better.
Good luck!
And sorry if this is not exactly an answer you wanted to hear :)

Please log in or register to answer this question.

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.