Game Development Reference
In-Depth Information
8.
Drag the Laser Light onto the Laser Point object in the Hierarchy view.
9.
Click Play, activate the laser, and test by running the laser over the various
scene objects.
The laser and light do well on most surfaces, but occasionally, the light cannot be seen. The issue
may be that the light is too close. On a flat surface, the light is on the same plane and its rays have
nothing to hit. If you want to refine the light's performance, you can make a second variable for the
hit distance minus a small offset and use that to position the light.
In the LaserBeam script, replace the hitLight.transform.localPosition line
with the following:
1.
Vector3 lightPos = new Vector3(0, 0,hit.distance-0.2f);
// calculate and offset from the hit pt
hitLight.transform.localPosition = lightPos;
// move the light to the hit point
2.
Save the script, and test.
You have probably noticed that the light never shines on the gate. If you watch the beam in the top
view as you point it at the gate, you will see that it stops short. Thinking back, you may realize that
there are colliders on the Occluder that trigger various events. This time, the solution is fairly simple.
There is already an Ignore Raycast layer that works internally and requires no extra scripting!
1.
Stop Play mode.
2.
In the Project view, assign the Ignore Raycast layer to the Occluder prefab.
3.
Check the objects in the Hierarchy view to make sure they now have the
layer assigned to them.
4.
Click Play, and test the laser on the gate.
This time. the beam goes all the way to the door and the light spot appears. Because the
GardenDoor material uses a simple Diffuse shader, the light spot is more subdued.
5.
Stop Play mode.
There are also several objects in the garden area that will block the laser from making contact with
the zombie bunnies. The Zombie Zone and the Plant Zones all have colliders that will intercept the
hits. Basically, any object that is not rendered but has a collider must be examined and possibly
excluded from raycast detection.
6.
Assign the Ignore Raycast layer to the Zombie Zone and each Plant Zone.
An additional special effect often used with lasers is sparks to let the player know when he has hit
something worthy. You will be using a Sparks prefab that has already been prepared for you. It is a
variation on the particle system that you created for a zombie-bunny hit. Feel free to check it out in
the Inspector.
 
Search WWH ::




Custom Search