Game Development Reference
In-Depth Information
4. Open the settings for the zombie object in the Inspector view and assign the settings
shown in FigureĀ 10.8.
FigureĀ 10.8
Settings for the
zombie's Character
Controller collider
5. Since the zombie mesh is made up of both the head and body objects, along with any
other objects from your Blender scene, the ProfessorZombie object has child objects in the
Hierarchy view. Click the arrow next to the zombie object to reveal these children.
6. Select the head mesh, which Blender names something like ProfessorZombie001 by
default. Rename the head mesh ProfZombieHead in the Hierarchy view and use the
Components b Physics menu to add a sphere collider to the head.
7. In the Inspector view, change the Center settings to 0 for the x value, -0.03 for the y
value, and 0.05 for the z value. Give the character controller a radius of 0.18 .
As you move game objects around your scene, remember to have local coordinates turned
on by using the Global/Local button at the top-left corner of the Unity interface. Otherwise,
you could place objects far away from their colliders, object centers, and parent objects.
8. In the Project view, use the Create menu to add a new JavaScript file to your Scripts
folder. Call this script ZombieStationary.js because you will use it to control a zombie
that stands idle until the player comes within range. If you are using the example
from the online resources, this code already exists in the ZombieStationary.js file in
the Scripts folder. If you are writing your own, open the script file by double-clicking
on it and add the code from the next section.
The ZombieStationary.js Script
he ZombieStationary.js script is the longest code you will use in this chapter, so it is bro-
ken up by function. Comments in the code, which are preceded by //, explain what each
part does.
The first section of the script defines variables that control elements of how the zombie
moves, elements such as how quickly it turns toward the player, how fast it is when it is
attacking, and how long it remains idle before initiating a new attack:
var attackTurnTime = 0.7;
var rotateSpeed = 120.0;
var attackDistance = 17.0;
var extraRunTime = 2.0;
Search WWH ::




Custom Search