Game Development Reference
In-Depth Information
Figure 15.28 Problem with triggers;
the raycasting is “seeing” the triggers,
and placing our EMP on them as well.
Layers
This is an annoying, but fixable, predicament. The triggers need to have a
collider on them or they won't work as colliders. But these colliders are what
cause the raycasting to see them, and then the ghosted EMP to crawl up the
sides of these imaginary objects.
Luckily, the fine folks at Unity have foreseen such troubles and created a
method of allowing objects to live on layers. These layers aren't like Photoshop
layers—they don't actually (by default) live in a particular order over the top of
each other. But they are very handy for Unity mechanisms that “see” things.
For instance, cameras and lights can be told to only “see” certain layers. For
lights this means that a light might illuminate certain objects
(that are on certain layers) and not illuminate adjacent objects (that are
assigned to different layers). It means that a camera could be told to ignore
certain layers and thus not to draw some objects that exist in the scene. This
can be a handy way to handle things like X-rays or night-vision goggles.
In the case of raycasting this can be very important. Via script, a raycasting
mechanism can be told to ignore certain layers, or, lucky for us, there is
already an Ignore Raycast layer that does some of this for us.
If an object, like a trigger, is assigned to this Ignore Raycast layer, all
raycasting functions see right through the object (they don't stop
the ray).
Which layer a GameObject is assigned to is seen in the Inspector and is right
next to the Tag drop-down menu. Creating new layers is actually within the
same mechanism as creating new tags (use the Layer drop-down menu to
select Create New Layer). We aren't going to be doing much with layers for
this project, but be aware that it's there.
Step 21: Assign each of the triggers to the layer Ignore Raycast. Do this
by selecting each trigger in the Hierarchy and then using the Layer drop-
down menu ( Figure 15.29 ).
Search WWH ::




Custom Search