In this section we'll learn how to toggle the transport on and off and change its speed using transport commands.
Note: This section continues with the configuration and script used in the previous section.
We can use the transport.setMovementSpeed command to scale the transport movement by any given factor. Add the following code and run the script again. Use the F5 - F8 keys to change speed:
The way the simulation is currently set up, the user can drive the car from any location in the environment. To make it more realistic, the script can be modified so the transport is only enabled when the user is inside the car. To do this we'll use the vizproximity library to detect viewpoint movements in and out of the car's bounding box area. Once a change is detected the transport.setEnabled command will be called and passed a parameter that turns it on or off. Don't worry about all the details of the proximity code below, that will be covered in later tutorials. For now, just notice how the transport state is set in the EnterProximity and ExitProximity callback functions.
Add the following code and run the script. Now, the transport only moves when the viewpoint is inside the car's bounding box area. Use the 'p' key to toggle the box's visibility: