# State machine for an Action/FPS game.

This topic is 3405 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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!

-ddn

##### Share on other sites
Thanks! I'll let you know how it goes.

##### Share on other sites
You may want to look at AiGameDev.com. If I remember correctly, they have quite a few articles on state machines (and various other approaches). Perhaps not animation-specific, but insightful nonetheless.

1. 1
2. 2
3. 3
4. 4
Rutin
12
5. 5

• 12
• 16
• 10
• 14
• 10
• ### Forum Statistics

• Total Topics
632659
• Total Posts
3007692
• ### Who's Online (See full list)

There are no registered users currently online

×