Sign in to follow this  

Implementing characters' actions

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have yet to find any literature on this topic. Take a fairly simple platform game, say, Castlevania 1. Simon the player character can perform a variety of different actions: standing, walking left/right, crouching, jumping, climbing up/down stairs, attacking with the whip/cross/ax/whatever, attacking while crouched, attacking on the stairs, getting hurt, and dying. In my project I've decided to handle these with a sort of state machine. My player character has a current action, which is changed by certain events like player inputs and interactions with the world. So while the character is performing the Idle action, pressing the Down key calls a function to change her action to Crouch, as well as set any other relevant variables like height and velocity. My code so far was not difficult and worked okay, but I'd like a more experienced opinion. Are there ways I can make it easier on myself to implement? Is this a sound technique or will I regret it later -- say, if I have a lot more actions to code? Will it last over many games or will I do better to find something different after this one?

Share this post


Link to post
Share on other sites
Thats perfectly fine in general, and greatly facilitates binding to an animation system. What you may want to consider as you branch into more complicated projects is expressing these state machines as a number of parallel state machines.

For example, there is the state machine consisting of {idle, run forward, run back, run left, run right, turn right, turn left, jump, crouch}, and a seperate and parallel state machine consisting of {idle, shoot, point and laugh, throw something, reload weapon}, with the statement that any action from the first type can be validly combined with any action of the second type. These sorts of separations will likely assist in you forming your animation systems that are a bit more flexable, and allow for you to cut things up more cleaning into little modular components as the number of potential actions grows larger.

Yes though, in general, this is a perfectly fine strategy, and is quite frequently used to describe these sorts of things. Many other strategies are just this same strategy with varying degrees of sophistication.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

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