WEBVTT

00:06.760 --> 00:14.050
In the previous lecture, we completed the Ice Star Searching Method here in our graph class.

00:14.080 --> 00:20.680
Now we need to do a reconstruct path so we can actually find the path from the start to the end.

00:20.680 --> 00:27.220
Because by the time we've done this searching through, we've linked up all of the nodes or waypoints

00:27.220 --> 00:34.420
together, and we're sitting with hold of the last one because we've basically created a linked list

00:34.420 --> 00:37.390
using the came from Node here.

00:37.390 --> 00:44.740
So we need to go back up that list and then we'll have the first node which a I character can follow

00:44.740 --> 00:45.160
forward.

00:45.160 --> 00:47.650
So we're going to call this reconstruct path.

00:47.650 --> 00:49.200
So let's put that back in.

00:49.210 --> 00:54.430
Now this is inside of our while loop down here when we've actually found a path.

00:54.430 --> 00:58.780
So it's going to be called reconstruct path and it's going to take the starting node and the ending

00:58.780 --> 00:59.380
node.

00:59.380 --> 01:05.820
So let's go and put that just down here so it'll be a public void.

01:05.830 --> 01:11.650
So it's not returning anything because it's actually setting that path list variable that we created

01:11.650 --> 01:12.520
early on.

01:12.670 --> 01:23.740
So reconstruct path and it'll have node, start ID and node and ID like that.

01:25.870 --> 01:26.110
Okay.

01:26.170 --> 01:29.710
So we're going to go path list dot clear case.

01:29.710 --> 01:31.780
We've already found a path previously.

01:31.930 --> 01:37.630
Then path list, dot add and ID.

01:38.920 --> 01:48.740
Then we'll go var p equals and id dot came from and then we can go.

01:48.760 --> 01:58.630
While P does not equal start ID and P does not equal null.

02:01.090 --> 02:10.540
Then we will go path list, dot insert and we're going to insert the next node that we find at position

02:10.540 --> 02:11.410
zero.

02:11.410 --> 02:21.130
So it's at the beginning of our list and then we will go P equals P came from so actually going up to

02:21.130 --> 02:23.380
the next node in our list.

02:23.470 --> 02:31.750
Finally, when we're finished, we will have path list dot insert zero.

02:33.640 --> 02:34.300
Start.

02:34.300 --> 02:38.080
I'd put that last one in there like that.

02:38.440 --> 02:41.170
Okay, so we're done with this graph class.

02:41.170 --> 02:42.190
Let's save it.

02:42.190 --> 02:46.960
Now, while I'm in here and thinking about it, let's just pop over to the node.

02:46.960 --> 02:48.190
The node.

02:48.190 --> 02:54.130
Remember, we added in this stuff here, we're actually not using it for anything because when we're

02:54.130 --> 03:00.850
doing our distance calculations, we're using the transformed position of our game object.

03:01.240 --> 03:07.330
If you weren't using game objects and you in some other kind of environment and you just wanted to pass

03:07.330 --> 03:12.220
through vector threes as the positions, then yes, you'd probably need to save it somehow.

03:12.220 --> 03:16.960
But for us, this kind of stuff is just a little bit superfluous because we're not using it.

03:16.960 --> 03:20.320
So let's just get rid of that and we'll save it.

03:20.440 --> 03:23.230
Now back to the graph just for one moment.

03:23.230 --> 03:26.560
That path list we just created, it's right at the top here.

03:26.590 --> 03:26.820
Okay.

03:26.830 --> 03:31.300
So we're going to use it over and over again basically, and set up our paths.

03:31.540 --> 03:40.870
So now it's time to actually program our graph in so we can pop back to the waypoint manager from where

03:40.870 --> 03:47.410
we left off about four videos ago and add in the code to process the graph.

03:47.410 --> 03:56.050
So first of all, we need a public graph graph and we'll make that equal a new graph, the top here.

03:57.100 --> 03:57.260
Okay.

03:57.400 --> 04:04.930
Then in start, we're going to add all of our nodes and edges based on what we've put into the inspector.

04:04.930 --> 04:17.170
So if way points dot length is greater than zero, then we will go for each game.

04:17.170 --> 04:21.370
Object waypoints in waypoints.

04:23.570 --> 04:29.870
And then graph dot add node WP like that.

04:32.120 --> 04:35.720
So that adds all of our nodes and then we'll go for each.

04:39.200 --> 04:42.440
Link ell in links.

04:43.910 --> 04:51.290
Then we will put graph dot add edge not node.

04:55.980 --> 04:59.490
From L dot node one.

04:59.490 --> 05:02.610
L dot node two.

05:04.620 --> 05:17.610
If l d r equals link dot direction dot bi, then that means we need to basically create an edge going

05:17.610 --> 05:20.010
back the other direction as well.

05:20.010 --> 05:23.490
Whereas if it's uni directional it just goes in one direction.

05:23.490 --> 05:32.880
So graph dot add edge l dot node two to l dot node one.

05:33.510 --> 05:38.670
This is really useful if you wanted to have like one way streets and things like that that you could

05:38.670 --> 05:43.470
make things go in just one direction along the path.

05:44.070 --> 05:46.020
Okay, so that's that code.

05:46.020 --> 05:47.040
Let's save it.

05:47.040 --> 05:47.430
Right?

05:47.430 --> 05:53.760
We're ready now to actually put some of those waypoints into the inspector.

05:53.760 --> 06:01.960
So if we go back into the inspector and when it's finishes compiling, click on our waypoint management,

06:01.980 --> 06:08.070
which is just here, you'll see that we have a link of waypoints, a list of waypoints, I should say.

06:08.070 --> 06:13.470
And we also have a list of links that we can put in here.

06:13.470 --> 06:17.310
So I'm not going to do that now, but I'm going to come back and do that in the next video.

06:17.310 --> 06:23.910
In the meantime, you might want to make sure that you've got a list of all your waypoints and which

06:23.910 --> 06:29.160
one connects to what, so that we can fill out the inspector here.

06:29.220 --> 06:29.700
Okay.

06:29.730 --> 06:31.200
I'll see you in the next lecture.
