#Player state machine

3 messages · Page 1 of 1 (latest)

main scroll
#

Hi there, I saw your code and your idea for state machine is quite good. Though I think I can consider a few improvs,

Lets start with the diagram....

In your grounded state, "StartJumping" must not be a state, Its more like represents an event.

Secondly, I would recommend you to keep the "OnAir" state specifically for what it sounds like. The "OnWall" state can be implemented with OnGrounded state ... for that you have to do some extra checks like surface alignment or any tags which can be associated with the wall such that it differentiates from regular walking/running surface.

Onto the code...

Try not to inherit Monobehaviour with your state class, instead use a manager to execute Do() function of the an active state.

Try to play with objects rather than conditions. Believe me, It really messes up code with some many if-else

Here follow this gut, he explains better than any university teacher

https://youtu.be/kV06GiJgFhc

Happy learning brother

Learn how to program a Hierarchical State Machine in Unity with this new video break down and tutorial!

Want to learn how to program state machines in Unity? This video will help get you there! Today we'll go over important concepts of the State Pattern and refactor our overly-complex code into a clean hierarchical state machine! With a detaile...

▶ Play video
manic plazaBOT
#

yithash thanked pkay1062