Game Development Reference
In-Depth Information
5.
To move the enemy drone toward the player character, you must assign
the current position of the drone, the point it is to proceed toward, and the
distance to be moved. The player character's Transform position is based
on his feet, so Vector3(0, 0.6, 0) is added so the drone will stay above the
surface of the elevated track but remain low enough that the player character
could still jump over it as an evasion tactic.
(6) transform.position = Vector3.MoveTowards(drone, target, distance);
6. The drone's new transform.position is calculated by the MoveTowards()
function by taking the drone's position, the player character's position, and
the distance to be moved as arguments.
Don't forget to add your cheat code to the CheckInput() function of the Cheats script for getting to
this zone quickly:
else if(Input.GetKey(KeyCode.Alpha7)) {
relocationPoint = Vector3(0, 9, 127);
RelocatePlayer();
}
Save the script and attach it to the Enemy Drone game object. The playerTransform property needs
to be populated in the Inspector, which can be done by dragging the Third Person Character Ragdoll
from the Hierarchy and dropping it into the property field. Playtest, adjusting the drone speed in the
Inspector until it is sufficiently challenging for you. Save the scene and save the project. Check it
out—all the killer zones of the Obstacle Course are complete. Great job!
Debugging
Unexpected behaviors, from catastrophic crashes to anomalies like the sparks not lining up with the
lasers you saw earlier in this chapter, are called bugs . Finding and fixing these problems is called
debugging . Unity has a special Debug class for just this purpose. You used the Debug.Log function
in Chapter 2 to display messages on the Console, and the Debug.DrawRay function in Chapter 7 to
make a raycast visible in the Scene view while testing. As your scenes and scripts become more
complex, you are more likely to see bugs, and also to identify and correct them efficiently.
Compiler Errors
When you click the Play button to run the game scene in the Game view, first the compiler translates
your script code so the processor can understand it. If the compiler finds errors in your code it will
let you know. The Unity compiler gives you a big notification in the Scene view of any such errors it
finds when you attempt to playtest (Figure 10-16 ):
 
Search WWH ::




Custom Search