Jump to content
  • Advertisement
Sign in to follow this  
Maxamor

State Machines -- How Detailed?

This topic is 4345 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

Hello all. I've read up on the state pattern and am ready to implement states into my Characters in-game. The game I am building is similar to old-school 2d-platformers (think Megaman). I am in a quandary trying to decided how many states to create and what should be considered a state. Take for example the ability to shoot. You can shoot in the middle of multiple states. You could be standing still and shoot. You can be running and shooting at the same time. You could be jumping or falling and shoot. These "shooting states" all have different animations. Would it be silly to implement ShootingWhileRunning, ShootingWhileStanding, and ShootingMidAir states? I would have to basically duplicate the code from the Running, Standing, and MidAir states just to change the animation. This does not seem like a good idea to me. How have you solved this problem?

Share this post


Link to post
Share on other sites
Advertisement
The system you described is not well-suited for a 'pure" Finite State Machine. (i.e. Yes, adding states like ShootingWhileRunning is silly.) Presuming that you're talking specifically about using an FSM to drive your animation system, a better alternative might be a variant FSM, such that (for example) there's a flag that indicates if the character is shooting or not, and certain states (such as Standing and Running) check that flag to determine which of several animations to display. (This is basically what Megaman actually does.)
For doing the AI, you may want to consider Rule Systems or Parallel FSMs (i.e. having multiple FSMs that each control different part of the object, for example one to control movement and one to control shooting behavior).

Share this post


Link to post
Share on other sites
Thanks for the input. About 10 minutes after posting I was looking at the diagram I had sketched up and realized that the shooting animation problem would be cleared by adding a boolean IsShooting and a double ShootingTimeElapsed.

As for the parallel FSMs for the Enemy AI, that sounds like a solid idea and I'll surely give it a shot.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!