Jump to content
  • Advertisement
Sign in to follow this  
shootdev

actor state

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

Hi guys, I'm building a game and would appreciate some guidance. Every object in my game is represented by an actor object which contains an instance of a state machine. An enemy in the game may have states like: run away, chase, seek cover In the case of the player I was wondering if I should map user input (keyboard) to a particular player state "a" key sets player state to "rotating left" "d" key sets player state to "rotating right", "space" key sets the player state to "shooting" However the player will often be rotating left, thrusting and shooting all at the same time - do I create mixed states "shootthrustrotateleft" or should I avoid using a state machine for mapping user input to player response?

Share this post


Link to post
Share on other sites
Advertisement
You can think of the player's update method as a state machine, but don't try to map all of the player's parameters to a single enum. Give your player variables like "isThrusting", "thrustSpeed", "isRotating", "rotateSpeed", etc. In your event handling code, modify those variables based on keyboard/mouse/joystick and then in your per-frame update move and rotate the player based on those variables. If you need logic that depends on the player being in the state MOVING or NOT_MOVING, or MOVING_AND_SHOOTING, or whatever then just test various variables for 0 or not-0 as appropriate.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!