AStar Pathfinding Issues (Aron Granberg)

Hi All.

I’m using Aron Granberg’s A* Pathfinding.

Basically what I’m trying to achive is:
A character to find the nearest target, then pathfind to the target.

The target is instatiated into the scene, based of an array of points (for it’s position). Then that position is pushed into another array

    var leakPositions = new Array(); // TODO! make me into a 'Builtin array'
    var activeLeaks = new Array();
    var leak : GameObject;
    
    leakPositions.Push(Vector3(-10,1,-21));
    leakPositions.Push(Vector3(-9,1,26));
    leakPositions.Push(Vector3(35,1,26));
    //plus many more
    
    function Start () {
    	//while(true) {
    		yield WaitForSeconds (4);
		
		var thePos : Vector3 = leakPositions[Random.Range(0, leakPositions.length)];
		var newLeak =  Instantiate( leak, thePos,  Quaternion.Euler(0, Random.Range(0,360), 0));
		activeLeaks.Push(newLeak.transform.position);
         //}
    }

So activeLeaks has the position of potential targets to pathfind to.

In another script, I calculate the closest target
(there is some other code that target the script above)
(TL:smile:R - closestPoint is a Vector3 point)

    function nearestLeak() {
    	if ( sprungleak.activeLeaks.length > 1) {
       	// and there's there is 2 or more active leaks
    		var dist : float = Vector3.Distance(gameObject.transform.position, sprungleak.activeLeaks[0]);
    		for( var i = 0; i < sprungleak.activeLeaks.length; i++ ) {
    			var tempDist : float = Vector3.Distance(gameObject.transform.position, sprungleak.activeLeaks[i]);
    			if(tempDist < dist) {
    				print("Closest Point is: "+sprungleak.activeLeaks[i]);
    				closestPoint = sprungleak.activeLeaks[i];
    				dist=tempDist;
    			}
    		} 
    	} else {
    		// there's only one leak. no comparison nessarary!
    		closestPoint = sprungleak.activeLeaks[0];
    	}
    }

Then I call the A* Seeker

   function Update () {
        nearestLeak();
        gameObject.GetComponent(Seeker).StartPath(transform.position, closestPoint, null, -1);
    }

And a Path is returned (and with the AStarPath debug path setting on, It’s there)

How to I move along this path? I’ve tried about 5 different ways, and trawled the internet to find and example or suggestion.

I know that A* creates an array of nodes, and that I need to iterate through them, while moving towards each node. I just can’t figure out how to access them.

What am I missing?

Using iTween you can do this in C#

My C# is a little rust (nay, non-existant).

To access PathComplete path I’d need to get the component they’re contained within (AStarPath.cs?)

I implemented both of those in the object that contains the Seeker component.

Hmm…

This is where I’m at (in JS)
doesn’t quite work

var seeker = gameObject.GetComponent(Seeker);
	// Called by Seeker on successful path computation
	 seeker.PathComplete( seeker.path ); 
		// Asks iTween to move the player along the path found by Seeker
		iTween.MoveTo( gameObject, iTween.Hash (
			"path", seeker.path,
			"orienttopath", true,
			"axis", "y",
			"speed", 25,
			"easetype", "easeInOutSine",
			"oncomplete", "onMoveToPathComplete"
		));

in JS it would be something like:

iTween.MoveTo(gameObject,{“path”:seeker.path,“orienttopath”:true,“axis”:y,“speed”:25,“oncomplete”,“onMoveToPathComplete”,“easetype”,“easeInOutSine”});

Best I can do since I don’t use Javascript