In the previous lecture, we completed the Ice Star Searching Method here in our graph class.
Now we need to do a reconstruct path so we can actually find the path from the start to the end.
Because by the time we've done this searching through, we've linked up all of the nodes or waypoints
together, and we're sitting with hold of the last one because we've basically created a linked list
using the came from Node here.
So we need to go back up that list and then we'll have the first node which a I character can follow
forward.
So we're going to call this reconstruct path.
So let's put that back in.
Now this is inside of our while loop down here when we've actually found a path.
So it's going to be called reconstruct path and it's going to take the starting node and the ending
node.
So let's go and put that just down here so it'll be a public void.
So it's not returning anything because it's actually setting that path list variable that we created
early on.
So reconstruct path and it'll have node, start ID and node and ID like that.
Okay.
So we're going to go path list dot clear case.
We've already found a path previously.
Then path list, dot add and ID.
Then we'll go var p equals and id dot came from and then we can go.
While P does not equal start ID and P does not equal null.
Then we will go path list, dot insert and we're going to insert the next node that we find at position
zero.
So it's at the beginning of our list and then we will go P equals P came from so actually going up to
the next node in our list.
Finally, when we're finished, we will have path list dot insert zero.
Start.
I'd put that last one in there like that.
Okay, so we're done with this graph class.
Let's save it.
Now, while I'm in here and thinking about it, let's just pop over to the node.
The node.
Remember, we added in this stuff here, we're actually not using it for anything because when we're
doing our distance calculations, we're using the transformed position of our game object.
If you weren't using game objects and you in some other kind of environment and you just wanted to pass
through vector threes as the positions, then yes, you'd probably need to save it somehow.
But for us, this kind of stuff is just a little bit superfluous because we're not using it.
So let's just get rid of that and we'll save it.
Now back to the graph just for one moment.
That path list we just created, it's right at the top here.
Okay.
So we're going to use it over and over again basically, and set up our paths.
So now it's time to actually program our graph in so we can pop back to the waypoint manager from where
we left off about four videos ago and add in the code to process the graph.
So first of all, we need a public graph graph and we'll make that equal a new graph, the top here.
Okay.
Then in start, we're going to add all of our nodes and edges based on what we've put into the inspector.
So if way points dot length is greater than zero, then we will go for each game.
Object waypoints in waypoints.
And then graph dot add node WP like that.
So that adds all of our nodes and then we'll go for each.
Link ell in links.
Then we will put graph dot add edge not node.
From L dot node one.
L dot node two.
If l d r equals link dot direction dot bi, then that means we need to basically create an edge going
back the other direction as well.
Whereas if it's uni directional it just goes in one direction.
So graph dot add edge l dot node two to l dot node one.
This is really useful if you wanted to have like one way streets and things like that that you could
make things go in just one direction along the path.
Okay, so that's that code.
Let's save it.
Right?
We're ready now to actually put some of those waypoints into the inspector.
So if we go back into the inspector and when it's finishes compiling, click on our waypoint management,
which is just here, you'll see that we have a link of waypoints, a list of waypoints, I should say.
And we also have a list of links that we can put in here.
So I'm not going to do that now, but I'm going to come back and do that in the next video.
In the meantime, you might want to make sure that you've got a list of all your waypoints and which
one connects to what, so that we can fill out the inspector here.
Okay.
I'll see you in the next lecture.