Vizard 7 » Tutorials & Examples » Avatars » Animating avatars » Tutorial: Using built-in animations
7.6

Tutorial: Using built-in animations

Avatars typically come with many different animations built into them. You can also add your own animations using 3DMax Character Studio. This tutorial will go over ways to use an avatar's given set of animations within your script.

Start the script

If you have trouble getting the code in this tutorial to work, you can find the complete example script avatarBuilt_In_Animations.py in the \tutorials\avatars directory.

 

To play with avatar animations, let's create a scene with a politician who is under your control. First add a little code to bring an avatar into the world:

import viz
import vizact

viz.setMultiSample(4)
viz.fov(60)
viz.go()

viz.clearcolor(viz.SKYBLUE)

#add the avatar and set his position and orientation
male = viz.addAvatar('vcc_male.cfg', pos=(0,0,4), euler=(180,0,0) )

Now let's animate the politician. To see what animations are available, open the avatar in Inspector using the Resources pane. Within Inspector, the avatars animations will be listed under the Animations pane (as seen below):

Now call a few of these animations using the vizact.animation action. When you create an animation action, refer to it by its place on the list of animations. For example, if you wanted your avatar to cheer and cheering is the third animation, you'd put the number "3" in the parentheses after vizact.animation.  Now we'll use vizact.onkeydown objects that will each handle different keys and add actions that will make our politician stand neutral, walk, or cheer.

#These keys will call various animations using the <avatar>.addAction() command.
vizact.onkeydown('1', male.addAction, vizact.animation(1))
vizact.onkeydown('2', male.addAction, vizact.animation(2))
vizact.onkeydown('3', male.addAction, vizact.animation(3))

Run this world and then press 1,2, or 3, to animate the avatar. Notice that the vizact.animation command only calls the animation once. To loop an animation continuously, use the state command. So, replace addAction( vizact.animation() ) with state in your script:

#change the animated state of the avatar
vizact.onkeydown('1', male.state, 1)
vizact.onkeydown('2', male.state, 2)
vizact.onkeydown('3', male.state, 3)

Run the script and go through your keys again.

 

Now let's make the politician look especially energetic by bumping up the speed of the animations with the speed command. The following line will double the speed at which he moves:

#change the speed of the animation
vizact.onkeydown('4', male.speed, 2)

To make him move at half the speed for a solemn occasion, add another key that replaces the doubled speed (2) with half the speed (.5):

vizact.onkeydown('5', male.speed, .5)

 

For additional examples, check out:

avatar

Adding an avatar

Animating an avatar

Using built-in animations

Using multiple animations

Animating avatar interactions

Smooth moves