0 votes

Watching some YT videos, watched to avoid the "Animator Hell": https://www.youtube.com/watch?v=nBkiSJ5z-hE

Then the Finite State Machine videos start to appear. So I tried to copy this: https://www.youtube.com/watch?v=Ty4wZL7pDME


but I do not understand quite well.

This is my project: https://github.com/chriztheanvill/Godot_CS_State_Machine

Its on Godot, with C#

Does not have the Assets folder:

Assets/Images/Character/Individual Sprite/

The thing is:

In the Implementation I repeat the code many times, like:

First get the parent object (Player) in to "pl" where there are the Methods:

Gravity, Movement, Jump, Attack, etc....

Walk, has the "pl.Gravity, pl.Movement, pl.Jump, pl.Attack" Methods.

Jump has the "pl.Gravity, pl.Movement, pl.Jump" Methods.

It is normal to repeat the methods in each state?

Godot version 3.4.2
in Engine by (26 points)

Can you show us the part in your code? Maybe I can tell you how to improve things.

1 Answer

0 votes

Yes, that's inherent to the pattern; although here, even more likely as there are many common things that overlap where as some complex state machine will have very different code. And that's fine, the pattern isolates the code making it easy to maintain and develop but ultimately the choice is yours.

There's some C# specific things that make the pattern simpler, such as first-class functions (also coming in godot). You could compare your state machine to other code, like this one I used in a game: https://github.com/spaceyjase/sr-6

by (418 points)
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 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 webmaster@godotengine.org with your username.