Tutorial: walking animation in Alice 2.2

The Alice 2.2 programming environment includes the heBuilder and sheBuilder objects that allow programmers to custom build characters. The other advantage of these objects is that they include a number of predefined animations, including a walking animation, together with several other animations. Now I’m a programmer, not an animator, so I welcome any pre-existing animations, and in my opinion the animations that come with these builder objects are pretty good.

The heBuilder and sheBuilder classes can be found in the gallery: look under Home > Local Gallery > People. The builder classes then enable you to build custom characters, by selecting various features. The interface is fairly straightforward, and is like the character builder for the Wii (not as many options though).

Alice shebuilder class

Once you have created a custom character, you can then make use of the pre-defined methods. Methods include a walking animation, together with several “emotion” animations, such as angry, confused, happy etc.

The following video tutorial demonstrates how these methods can be used. To do this we use several “when key is pressed” events to control the character. To get the character to walk forward we combine the walking animation with the move forward method.

Walking while key is pressed

Programming the character to walk when the key is pressed is fairly straightforward and is described in the video shown above. However programming the character to walk while the key is pressed is not so easy. If we try to call the same walk forward method that we use for the “when key is pressed event” the program generates an exception. This is because the while key is pressed event stops executing the code that it executes while the key is pressed as soon as the key is released. This is problematic for the walk method – terminating the method mid-way through leads to this execution. What we need is some way to finish executing the code in the walk method.

To do this we introduce a simple two-state finite state machine. The states for this FSM are walking and idle. Whenever the FSM is in the walking state, we run the walking animation. Whenever the FSM is in the idle state the walking animation is not run. To represent the state we use a boolean valued variable, called walking. The variable is true when the FSM is in the walking state and false otherwise. If there were more than two states we would need to represent the state in another way – perhaps using a string.

Putting this all together, we use the “While key is pressed event”. At the beginning of event we change the walking state to true. This triggers the walking animation action. During the key press event the character moves forward. At the end of the key press event the walking state is changed to false. At this point the walking animation action is stopped, but not until the code for the current call is completed, thus avoiding the termination of code mid-way through.

Ok, that is probably all a bit convoluted, so lets go to the video.

Posted on November 4, 2011, in Tutorials and tagged , , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: