I'll use Link to the Past as an example
link1.jpg 11.34KB 50 downloads
Link takes out his sword and begins the attack animation. Though the sword is being rendered, it has no hitbox yet. For the next couple of frames, pressing the d-pad or any buttons will have no effect on Link.
link2.jpg 16.87KB 47 downloads
The sword now has a hitbox and can collide with enemies.
link3.jpg 17.3KB 39 downloads
The player can now press attack to interrupt the current attack animation and start a new one. Any other input is still ignored.
link4.jpg 19.51KB 44 downloads
On the last frame of the animation (13), the game checks to see if the attack button is held down. If it is, Link enters a new state where he begins charging his sword. If not, on the next frame, the animation ends, the sword disappears, and full control is given back to the player.
I'm wondering, how would people approach the problem of implementing "actions" like these in a video game? Where rather than the action taking place in a single frame, it takes place over several frames and updates certain things(like the position of the sword is always attached to link's hand, even if he is moved by some outside force during the animation) each frame. With access to today's technologies of course.
Best i can come up with for an "attack" action is hard coding it based on states. Pressing attack puts Link in the "Sword Attack" state and starts a timer. The game sees this, then creates the sword and starts playing out the animations. Each frame, the game updates, checks the time passed to see if it should add the hitbox or whatever it needs to do. The second half of the animation would have its own state, so the game knows that it is allowed to accept input for another attack to interrupt the current one.
That means coming up with a different set of states for every action in the game though, which would be a pain. Especially in a component+entity system, where you would need to add the code into a State System or something instead of each entity's own update method. So i'm wondering to see if there are better ways to handle this, especially more data-driven ways.