Game Development Reference
In-Depth Information
The character in this instance will move between the positions of
waypoints. If you have placed your spheres on the ground, the character
will sink into the ground as it is aiming its (0,0,0) position, which is
in the center of the model, to the (0,0,0) of the sphere. To make the
character appear to be moving on the terrain, move the spheres up to
the right height. You can do this collectively by selecting all spheres in
the Hierarchy by holding down shift while clicking on them and then
dragging them up in the Scene.
In addition, if a character ever gets to a waypoint and starts circling
it unexpectedly, it will be the accuracy setting. You may have it set
to small; if the character can never get close enough to a waypoint it
will just keep trying. In this case, set the accuracy value to something
Step 9. Using the A* algorithm to calculate a circuit is a little bit
of overkill, as a circuit can be performed simply using the code
from Chapter Three. So now we will put it through its paces
by adding some more button commands to get the character
to move about the building. Modify the patrol code to that in
Listing 5.7 .
Listing 5.7 Testing A* Pathfinding by Giving Movement
Commands to a Character
var waypoints: GameObject[];
var graph: Graph = new Graph();
var currentWP: int = 0;
private var currentNode: GameObject;
private var speed: int = 8;
private var rotationSpeed: int = 5;
private var accuracy: Number = 1;
function OnGUI ()
GUI.Box (Rect (10,10,100,140), "Guard's Orders");
if (GUI.Button (Rect (20,40,80,20), "Patrol"))
this.animation["run"].wrapMode = WrapMode.Loop;
if (GUI.Button (Rect (20,65,80,20), "Front Door"))
currentWP = 0;
Search Nedrilad ::

Custom Search