Game Development Reference
In-Depth Information
{
graph.AStar(waypoints[0],waypoints[8]);
this.animation.Play("run");
this.animation["run"].wrapMode = WrapMode.Loop;
}
}
function Start ()
{
...
}
function Update()
{
//draw the paths in the scene view of the editor while playing
graph.debugDraw();
//if there is no path or at the end don't do anything
if(graph.getPathLength()==0 || currentWP == graph.
getPathLength())
{
this.animation.Play("idle");
return;
}
//if we are close enough to the current waypoint move to next
if(Ve ctor3.Distance(
graph.getPathPoint (currentWP).transform.position,
transform.position) < accuracy)
{
currentWP++;
}
//if we are not at the end of the path
if(currentWP < graph.getPathLength())
{
//keep on movin'
var direction =
graph.getPathPoint(currentWP).transform.position −
transform.position;
transform.rotation =
Quaternion.Slerp(transform.rotation,
Quaternion.LookRotation(direction),
rotationSpeed * Time.deltaTime);
transform.Translate(0, 0, Time.deltaTime
* speed);
}
}
Step 8. Play. When the Patrol button is pressed the A* algorithm will
calculate a path between the first and last waypoint and the guard
will start running around it.
Search Nedrilad ::




Custom Search