Vizard 8 » Tutorials & Examples » Flow control » Actions » Tutorial: Creating an action
8.0

Tutorial: Creating an action

In our example, we want the wheel barrow to move forward a certain amount, turn to the right, move forward again, turn right, and repeat until it reaches its original position. The first thing we need is an action that will move the wheel barrow forward. The vizact library has an action called vizact.move(), which will move an object in a given direction for a specific amount of time:

 

For our example, let's move the wheel barrow forward at 2 meters per second for 1 second. The following code will create this action:

moveForward = vizact.move(0,0,2,1)

The first 3 arguments of the move command are the direction we want to move. Since we want to have the wheel barrow move forward, we only need to set the value for the Z axis. Setting the Z axis value to 2 means that the object will move along its local Z axis at 2 meters per second.  The fourth parameter controls how long we want the object to move, which is 1 second in this example. We saved the new move action in a variable called moveForward.  We can add this action to any 3D object now.

 

After the wheel barrow is finished moving it needs to turn right 90 degrees. To do this we will create a spin action with the vizact.spin() command. The following code will create this action:

turnRight = vizact.spin(0,1,0,90,1)

The first 3 arguments represent the local axes that we want the object to spin around.  For this example, the object will rotate around its local Y axis. The 4th argument represents how fast we want the object to spin. Setting the value to 90 means that the object will spin at 90 degrees per second. The last argument specifies how long we want the object to spin for. Since we want the object to turn to the right, we only need to spin it for 1 second, since the speed is 90 degrees per second.

Action objects

Building an action

Applying an action