Skip to content

Instantly share code, notes, and snippets.

@ricardojmendez
Created February 24, 2011 08:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ricardojmendez/841909 to your computer and use it in GitHub Desktop.
Save ricardojmendez/841909 to your computer and use it in GitHub Desktop.
Draft seeker using AngryAnt's Path 2
using System.Collections.Generic;
using UnityEngine;
using UnitySteer;
/// <summary>
/// Steers a vehicle to follow a path
/// </summary>
/// <remarks>
/// Based on SteerToFollowPath.
/// </remarks>
[RequireComponent (typeof (Navigator))]
public class SteerForAngryAntPath : SteerForPathSimplified
{
#region Private fields
Path _angryAntPath;
#endregion
#region Public properties
/// <summary>
/// Path to follow
/// </summary>
public Path AngryAntPath {
get {
return this._angryAntPath;
}
}
#endregion
#region Path event handles
void OnNewPath (Path path)
// When pathfinding via Navigator.targetPosition
{
Debug.Log("PATH DONE " +Time.realtimeSinceStartup);
Debug.Log ("Received new Path from " + path.StartNode + " to " + path.EndNode + ". Took " + path.SeekTime + " seconds.");
_angryAntPath = path;
var collect = new C5.ArrayList<Vector3>();
foreach (var s in path.Segments)
{
collect.Add(s.To.Position);
}
collect.Add(path.EndPosition);
Path = new Vector3Pathway(collect, 0.5f, false);
}
void OnTargetUnreachable ()
// When pathfinding via Navigator.targetPosition
{
Debug.Log ("Could not pathfind to target position");
_angryAntPath = null;
Path = null;
}
void OnPathAvailable (Path path)
// When pathfinding via Navigator.RequestPath (startPositio, endPosition)
{
Debug.Log ("Requested Path from " + path.StartNode + " to " + path.EndNode + " is now available. Took " + path.SeekTime + " seconds.");
}
void OnPathUnavailable ()
// When pathfinding via Navigator.RequestPath (startPositio, endPosition)
{
Debug.Log ("The requested path could not be established.");
}
void OnPathInvalidated (Path path)
// When a path requested by a Navigator on this GameObject is no longer valid - due to a connection or node disabling or removal
{
Debug.Log ("The path from " + path.StartNode + " to " + path.EndNode + " is no longer valid.");
}
void OnDrawGizmos()
{
if (_angryAntPath != null)
{
_angryAntPath.OnDrawGizmos();
}
}
#endregion
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment