Using Sensors
A number of nice items are rejected each week because they have continuously
running animations. Continuous animations require a great deal of computer processing
power, and are a particular burden because the calculations have to be performed,
even if the object isn't currently in view. You can be standing in your virtual
rooftop garden, while a continually running hamster in your vitual basement
is using up all of your computer's power. This causes a jerky frame rate in
your world animation, and spoils the illusion of moving through a 3D world.
For this reason, VRML provides several types of sensor you can use to control
when animations will run.
- TouchSensors, which are triggered when an object is clicked.
- VisibilitySensors, which are triggered when the sensor comes into view.
- ProximitySensors, which are triggered when an avatar enters the sensor's
area.
Here are some tips for creating sensors in Spazz 3D.
Adding a Sensor
Add a sensor to your Spazz world by clicking the sensor icon
(you can also add a sensor using Create|CreateSensor).
Once you have the sensor in your world, you can use the Properties dialog to
set the sensor type.
TouchSensor
TouchSensors affect all items in a group (including a Transform or Collision
group), and all of its child groups (subgroups). If you put a TouchSensor in
the Ground node, then anything you click in the entire world will trigger the
sensor. If you put the TouchSensor into a subgroup, only when you click an item
in that group will the sensor trigger an event (such as starting an animation).
For example, to make a button, you can create a small cylinder, put it into
a group, then add a TouchSensor to the group. When the cylinder is clicked,
it will trigger an event.
To use a TouchSensor:
- Insert a Sensor node.
- In the Properties dialog, be sure it's set to TouchSensor (which is the
default).
- In the World Tree, drag the sensor into the group that should be clicked
to trigger the animation (either the entire world, or a subgroup). Note that
the position of the sensor doesn't make any difference - only the group that
contains it will determine how it is triggered.
- Set the animation triggers.
- Click the Sensor in the Project tree.
- Open the Properties window.

- Click the Add Trigger button.
- In the Project tree, click the animation node that you want to start with
the TouchSensor.
- Set the Trigger information in the Trigger List. Most often, you want
to use a Toggle, which starts the animation on the first click and stops
the animation on the second click (like a light switch, it turns the animation
on and off). You can also start the animation from the beginning if it is
a short animation that stops when it's finished. If it's a looping animation,
use a Toggle switch so that the owner of the object can turn the animation
off when s/he isn't using it.
- Save your work.
- Test your work using the Browser simulator or by exporting the file as a WRL and running it in your blaxxun Contact browser.
VisibilitySensor
VisibilitySensors are a good choice for something like an animal in a cage,
fish in an aquarium, or the water in a fountain. Objects like these are assumed
to be continually in motion, so your customer would expect it to be moving when
they're looking at the object. What they don't need to know is that the animation
stops the moment they stop looking at it.
To use a Visibility Sensor:
- Insert a Sensor node.
- In the Properties dialog, change the setting to VisibilitySensor. A blue
outline appears in your project window, showing you the placement of the sensor.
- In the Properies dialog, set the Proximity Size of the sensor so that it
completely covers the visible animated portion of your object. You may need
to move the sensor using the Trans panel of the dialog - unlike the TouchSensor,
the position is key to creating a VisibilitySensor.

- Set the Triggers.
- Click the Add Trigger button.
- In the Project Tree, click the animation node you want to trigger with
the VisibilitySensor.
- Set the trigger options so that when the sensor becomes visible, the triggered
animation will Start at the beginning.
- But you're not finished yet - click the Add Trigger button once again.
- Click the same animation node.
- Set the Trigger List options so that when the sensor becomes not visible
the animation will stop. This way, the animation will only run if someone
is watching.

- Save your work, and test the results in the browser simulator, or export
the file to VRML and test it in blaxxun Contact. Make sure that the animation
runs when you look at it. You'll have to take it on faith that it stops when
you aren't looking, though you may notice that your computer becomes a little
more performant when you aren't looking at the animation (because it isn't
doing all the extra work).
ProximitySensor
A ProximitySensor is a good sensor to use when the animation is too small to
be seen from a distance (this is also the sensor you would use to create an
automatic door that opens the door when someone stands next to it). You can
set the ProximitySensor to about 10 yards, which will probably start the animation
well before anyone can see it.
To use a Proximity Sensor:
- Insert a Sensor node.
- In the Properties dialog, change the setting to ProximitySensor. A blue
outline appears in your project window, showing you the placement of the sensor.
- In the Properties dialog, set the Proximity Size of the sensor so that it
surrounds and allows for a good deal of space around the animated object.
In this case, it's the position of the viewer's avatar that will trigger the
animation, so you want it to be large enough to fit the avatar and enable
the viewer to see the animation from that vantage point (if the Proximity
Size is too small, the animation may not start until the viewer is too close
to see it).

- Set the triggers.
- Click the Add Trigger button.
- In the Project Tree, click the animation node you want to trigger with
the ProximitySensor.
- Set the trigger options so that when the sensor region is entered, the
triggered animation will Start at the beginning.
- But you're not finished yet - click the Add Trigger button once again.
- Click the same animation node.
- Set the Trigger List options so that when the sensor region is exited,
the animation will stop. This way, the animation will only run if someone
is close enough to see it.
- Save your work.
- Test your work using the Browser simulator or by exporting the file as a
WRL and running it in your blaxxun Contact browser.
That's it! Use these techniques, and you will not only make an item that works
better in Cybertown, you'll most likely make an item that will sell better,
as well.
Back to Creating Objects for Cybertown
Send your comments on this page to Epistomolus.
Updated February 23, 2007