I'm having a bit of an architecture dilemma. I'm trying to decide how I should control the animation of my little robot character. Here's the scenario:
Where I'm having trouble is in sequencing the animations. Should I use a Coroutine to animate the rotation and then once complete start the move Coroutine? Or should I set up a state machine and just check if the robot is in the right state on update (Idle, Rotating, Moving)?
I feel like the state machine is probably the more traditional way to do it, but I wanted to get some other opinions.
asked Jul 15 '11 at 01:03 AM
Well, if the task is not interruptable a coroutine would work fine. If you want to be able to stop the process at any time a state machine would be better ;). A coroutine is really useful when you have a quite linear command chain.
Just in case you didn't know: coroutines are also statemachines but the state-handling is hidden. The compiler even creates a whole seperate desicated nested class for each coroutine. Since the state-stuff is not accessible, coroutines are not as flexible as own statemachines ;)
answered Jul 15 '11 at 02:57 AM
I'd say that every Update event, the robot should calculate afresh whether it needs to turn or move forward. So a modeless solution. Only if that choice was expensive to make would I use a modal approach. The trouble with the modal approach is that you then need more code to kick it out of the mode (eg. when player chooses new tile before robot reaches first choice).