Next we're going to learn how to control events in our world. We'll do this by adding keyboard interaction. The vizact library has commands to handle a variety of events, including keypresses and timer events.
We'll do this by using vizact.onkeydown() to listen for a specific keypress and call the appropriate function when it occurs.
First, we define a walkAvatars function that gets called when the 'w' key is pressed. This will add walking actions to the human avatars using the vizact.walkTo command. This command takes a [x,y,z] target location as an argument. The locations specified here are on the other side of the piazza through the arch. The female's walk action is applied 0.5 seconds after the male's walk action. This accounts for the time it takes the male to turn toward the arch so they walk out side by side. Add and run the following code to see this in action.
Next, we define a pigeonsFeed function that gets called when the 'p' key is pressed. When the event occurs a repeating sequence of actions (walk, change animation, wait) is applied to each pigeon to replicate walking and feeding behaviour. By generating random parameters for each action the result is movement that looks quite natural. This code is introduced to demonstrate the power of actions so you don't need to worry about the details at this time. Add the following code and run the script:
This concludes the Vizard Introduction. From here, you can either follow through the tutorials in order or pick and choose the ones that focus on your areas of interest.
Have fun!
The WorldViz team