Vizard 5 » Tutorials & Examples » Avatars » Animating avatars » Tutorial: Animating an avatar

Tutorial: Animating an avatar

Now let's make the avatar walk to wherever we click on the ground. To do so, we need to register a function that will be called when a mouse button is clicked.  We'll use vizact.onmousedown() for this.


def avatarWalk():
    info = viz.pick(1)
    if info.valid and info.object == ground:
        walk = vizact.walkTo([info.point[0],0,info.point[2]])

vizact.onmousedown(viz.MOUSEBUTTON_LEFT, avatarWalk)


Note: Python uses indentation as a structural element of the language. Make sure when writing your own code that the indentation is consistently either tabs or spaces, not mixed. You can make the tabs / whitespace visible in Vizard with View >Whitespace.


When the left mouse button is clicked the function avatarWalk() is called.  The first part of the code simply checks that the user clicked on the ground. If it was, then a walkTo action is created to the point that was clicked.  Then runAction() is used on the avatar which is equivalent to clearing any actions in its queue and adding the new action.  This way, wherever you click, the avatar will immediately begin walking to that point rather than waiting to finish any other walk actions.


Now run the script and click anywhere on the ground and the avatar will walk to that point.


For additional examples, check out:



Adding an avatar

Animating an avatar

Using built-in animations

Using multiple animations

Animating avatar interactions

Smooth moves