Now let's create a new world in which our avatars interact. In this script, we will use both our female and male characters. We will have the female shout to the male and have the male dance in response.
If you have trouble getting the code in this tutorial to work, you can find the complete example script avatarInteractions.py in the \tutorials\avatars directory.
First, let's create a world and add the avatars:
Next, we set the position and orientation of the viewpoint so we can see both avatars clearly.
In order to have the male begin dancing after the female has completed shouting we need to know the duration of the female's animation. To do that add the following to your script.
Next, we add two functions and use vizact.onkeydown to listen for a keypress. When key 1 is pressed the sheShouts() function is called. This starts the shouting animation and a timer using vizact.ontimer2. With vizact.ontimer2 a timer will expire after the SHOUT_DURATION time and call the heDances() function. The second argument there specifies how many times to repeat the timer, in this case we only want the timer to expire once, so that is set to 0. The dancing animation is then added to the male avatar within heDances(). Run the script and press 1 to see this in action.
For additional examples, check out: