Sign in to follow this  
shootdev

actor state

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

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