Sign in to follow this  

State machine for an Action/FPS game.

Recommended Posts

I'm currently designing an FPS and I've got a pretty good idea of what I want to do for all the features except one part I'm a bit stuck on which is handling the player stats based on the current player action, basically how to handle the player actions so that no illegal combinations occur but I also want the ability to call the change between states by using functions as well has having a state for each of these transitions between states. For example Dive in the following diagram needs to have separate properties from both Spriniting and prone for the duration of the action. As you can see actions like jump, while being similar to other states require a different excecution, i.e the state is volatile and has a memory of the state it came from, also going from Sprinting to Walking or vice versa needs to take a certain amount of time in which the player attributes change dynamically along with the time since the state was changed. My current solution is a continually refreshing function which first checks if the player is performing any actions and changes the players parameters accordingly checking variables for time occured since action started and player state otherwise it chacks the main state the player is in and takes parameters from that. The problem with this is that it requirea a very large select function and it's not a very elegant solution and restrictions on other actions such as aiming and shooting need to be imposed manually for each condition. Does anyone know of a better way to do this?

Share this post

Link to post
Share on other sites
Animation engines are pretty complex now, they define the animation states of a character in a hierarchical tree form. So in your case a tree something like this

roll--prone--stand---crouch--stealth walk
| | \
shuffle walk sprint
| \
jump jump

where stand is the root node, there are other transitions but it's difficult to show using ascii, there is one from jump->stand ( there are 2 types of jump if u noticed, walking jump and sprinting jump )

Basically inputs drive the states, the current state your in can be a transitory ( ie the jump state and automatically transitions out of that state based upon rules governing that state )

Read up about state machines and how they work, then read up about hierarchical state machines. These trees aren't strict hierarchical states machines, since the state are much looser, as you can arbitrarily transition to any other state at almost anytime conditionally ( ie in mid walk u get hit by a train and have to transition into get hit by train state )

Good Luck!


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this