Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
0
1
00:00:00,240 --> 00:00:04,020
Let's now look how to implement the navigation mesh in Godot.
1
2
00:00:04,440 --> 00:00:07,560
If you use 3D objects to define your terrain, you're in luck.
2
3
00:00:07,590 --> 00:00:10,880
Godot provides a solution for you out of the box.
3
4
00:00:10,890 --> 00:00:12,280
Enter: navmesh.
4
5
00:00:12,300 --> 00:00:19,380
It's quite easy to create and use a navmesh. Because Godot provides two key nodes for it and these
5
6
00:00:19,380 --> 00:00:25,170
are the navigation node and the navigation mesh instance.
6
7
00:00:25,180 --> 00:00:31,380
By putting this node and the child node navigation mesh instance, we can generate the navigation mesh
7
8
00:00:31,380 --> 00:00:34,200
by running the bake navmesh.
8
9
00:00:34,590 --> 00:00:37,770
Of course, for this we definitely need more of this.
9
10
00:00:37,860 --> 00:00:42,480
So I'll quickly create a small environment that we can run our navigation mesh.
10
11
00:00:53,910 --> 00:00:58,290
Now that we have these in place, we need to select the navigation mesh instance.
11
12
00:00:58,290 --> 00:01:03,090
And as you can see, there is a small error here because it needs an actual navmesh specified here.
12
13
00:01:03,090 --> 00:01:10,500
But don't worry, by just creating a new navmesh and hitting the bake nav mesh, Godot will automatically
13
14
00:01:10,500 --> 00:01:14,400
generate this awesome navmesh for us to use.
14
15
00:01:14,400 --> 00:01:21,840
Of course, to actually get the position from a point to another point, we need to use a particular
15
16
00:01:21,840 --> 00:01:25,290
instruction. Let's find out how to implement that as well.
16
17
00:01:25,290 --> 00:01:32,160
So first, I'll need to create another mesh instance, which would be our player and our player would
17
18
00:01:32,160 --> 00:01:33,570
be just the capsule.
18
19
00:01:35,490 --> 00:01:36,740
Make it a little smaller.
19
20
00:01:55,120 --> 00:01:56,500
And I'll give it a script.
20
21
00:02:07,230 --> 00:02:13,650
So what we need to do here is, of course get the reference to this navigation and this can be done
21
22
00:02:13,650 --> 00:02:16,070
at the start of the sequence.
22
23
00:02:16,080 --> 00:02:24,180
So navigation will call it get the parent because the parent of this is the navigation and then we'll
23
24
00:02:24,180 --> 00:02:28,890
use a get_custom_path(target_position).
24
25
00:02:29,070 --> 00:02:39,180
We run the path from that target position so we can generate it by calling nav get simple path and then
25
26
00:02:39,180 --> 00:02:42,480
we need to specify the start and the end of the path.
26
27
00:02:42,810 --> 00:02:46,260
The end is the target's position and the start is where the player is.
27
28
00:02:55,020 --> 00:02:59,940
And basically this is it, of course, to be able to test it, we need to go back into the scene.
28
29
00:03:00,940 --> 00:03:09,520
And let's create another position3D, which would be the target in our case, and let's put it around
29
30
00:03:09,520 --> 00:03:09,910
here.
30
31
00:03:13,150 --> 00:03:14,020
I'm going to.
31
32
00:03:17,820 --> 00:03:19,050
Call it in _ready().
32
33
00:03:19,050 --> 00:03:21,400
So I'm just going to print out.
33
34
00:03:21,570 --> 00:03:24,930
Get a custom path from the...
34
35
00:03:26,450 --> 00:03:36,530
Of course, I need to go back one level because the player is up one level. Target/. And then we need
35
36
00:03:36,530 --> 00:03:37,070
to.
36
37
00:03:40,520 --> 00:03:41,580
Get the position.
37
38
00:03:43,340 --> 00:03:52,550
And by doing this and calling this, we will end up with a list of positions of vector3 that the
38
39
00:03:52,550 --> 00:03:59,720
player needs to take in order to go from the initial point to the target that we specified.
3998
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.