Jump to content
  • Advertisement
Sign in to follow this  
rpiller

Player input design in relation to actions and animations

This topic is 2499 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 really enjoy thinking about different ways to design systems. Currently I've been liking event driven design but need some help with a design or thoughts about how it could be done. If you take away the polling of things and make things more event driven input becomes more about calling a function once instead of continuously. In the case of player input and what the input actually does I generally have difficult with the stopping of an action when the key is let go in situations like movement.

For example, I have an InputManager class. This class hides the keybindings to actions. For example a configuration could be if I press the W key I want to do the MoveForward action on an Actor class. The MoveForward action also starts a certain animation like "walk" for instance. The problem revolves around letting go of the W key. It needs to then call the Stop action and StopAnimation on the "walk" animation.


So I use games that let you configure as inspiration. WoW for example lets you like keys to actions. The thing I'm having a little trouble with getting a "good" design is the actions that run while the key is held down, and need to stop when the key is released. Some code on how I bind the MoveForward action to an actors MoveForward function which will set it's move variable which is used in the Actor's update method to actually move it. To me this looks like a very nice design, but with this alone the actor will never stop, yet in games like WoW it's not like you map a StopMoveForward action to a key. Certain things are just assumed. So given something like the below mapping of input action to actor action, how would you complement this to stop the actor from moving using event driven ideas.

// let's assume the OnMoveForward key behind the inputMgr is mapped to 'W'
inputMgr->OnMoveForward.Bind(actor, &Actor::MoveForward);

Things like:
inputMgr->OnMoveForwardStop.Bind(actor, &Actor::StopMoveForward);

just don't seem right to me. I'm just curious if anyone can think of a more eligant way to handle this using event driven methods.

Share this post


Link to post
Share on other sites
Advertisement
Just bind one function, but have as a parameter to that function a bool, like IsKeyDown, which defines if the key has just been pressed, or it's just been released.

So, you could do this:

class Actor
{
...
// these are called when a movement key is initially pressed, and when it is released
void MoveForward(bool IsKeyDown);
void MoveBackward(bool IsKeyDown);
...
};

...
void Actor::MoveForward(bool IsKeyDown)
{
if (IsKeyDown) {
// begin walking sequence
}
else {
// Stop moving forward
}
}

...

inputMgr->OnMoveForward.Bind(actor, &Actor::MoveForward);

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!