SHARE
TWEET

PirateAI

a guest Jan 18th, 2014 315 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if (target != null) {
  2.         Stack<GameObject> path = DijkstraAlgorithm.Dijkstra (
  3.                 GameObject.FindGameObjectsWithTag ("Node"),
  4.                 gameObject.GetComponent<CurrentNode> ().currentNode,
  5.                 target.GetComponent<CurrentNode> ().currentNode);
  6.  
  7.         GameObject goal = path.Pop ();
  8.         Debug.Log (goal);
  9.         Vector3 goalPosition = goal.transform.position;
  10.         Vector3 goalDirection = goalPosition - transform.position;
  11.  
  12.         if (transform.position.x < goalPosition.x) {
  13.                 transform.Translate (Vector3.right * speed * Time.deltaTime);
  14.         }
  15.         if (transform.position.y < goalPosition.y) {
  16.                 transform.Translate (Vector3.up * speed * Time.deltaTime);
  17.         }
  18.         if (transform.position.x > goalPosition.x) {
  19.                 transform.Translate (Vector3.left * speed * Time.deltaTime);
  20.         }
  21.         if (transform.position.y > goalPosition.y) {
  22.                 transform.Translate (Vector3.down * speed * Time.deltaTime);
  23.         }
  24. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top