NavMeshLink in Unity - Adding Jumping to NavMeshAgents | AI Series Part 2 | Unity Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] welcome to lomacademy chris here to help you yes you make your game dev dreams become a reality this is the second part of our ai series where we're talking about nav mesh links that's how you connect two parts of a nav mesh together or you can even jump from one nav mesh to a completely different nav mesh if you haven't checked out the previous video part one of the series where we go into how to set up a nav mesh what the agents are the different components all that stuff if you haven't checked that out there's a card on the screen right now go check it out because we're building on that in this video we're taking that scene we're changing a little bit and adding nav mesh links so if you're just jumping in here uh it might be a little bit weird so go back check it out and then come back and check this one out let's hop in and add a nap mesh link to our demo scene if you're following along from the last video the only change here is i've moved the camera position a little bit and i've duplicated the entire world geometry so everything floor through wall 13. i just selected all that duplicated it and moved it over to the right a little bit that's it if i select all of the world geometry we'll see that actually the nav mesh see i haven't even baked the nav mesh yet so what i'll do is select world geometry and just click bake on both the player nav mesh surface and the enemy nav mesh surface and we'll see that cool i have two different nav meshes or two different sections of nav meshes but there's no way for them to be connected so if i clicked play and tried to click on the right section of floor my nav agent would run to the wall and just kind of stand there to create a new game object and attach a nav mesh link to it we'll see that we get a few options here the agent type start point endpoint width cost modifier auto update position bi-directional and area type the start and end point define where the agent will first hook up to the link and then cross towards the end point if you define a non-zero width it allows the agent to cross over a range of positions anywhere within that width it will allow the agent to jump across there here we're keeping it at zero but we could potentially make it the entire width of our floor to allow the agent to cross anywhere on the side where there is a valid link on the other side the cost modifier most of the time you probably want to leave it at 1 it should be a non-negative number and it's defined as the non-negative cost of moving over the navmesh link which is this number times the euclidean distance between that mesh link endpoints so if you don't know what that means leave it at one if you do know it that means well then you probably know what it should be set to basically the lower values will make it easier and higher probability that the agent will cross there auto update position just indicates whether the link should control the agent's position as it crosses it if you turn that to false you need to manage the nav mesh agent's position bi-directional makes it so you can either have one way or two way jumps we'll be using only two-way jumps in this demo if you turn off bi-directional it's really important that you align the start and end point correctly and the ui that you see will have an arrow only going one way so it'll help you out and the area type is the exact same as we saw in the navmesh agent probably want to be jump unless you have custom areas and define the nav mesh link to be a non-jumping link what i'm going to do is align this where i have that green line going across the floor that way the player knows where they can jump across it's really important to align the start and end point to be on the nav mesh if it's not on the nav mesh the agent will not be able to use it and the agent will understand that it cannot use that link if i click play and click on the right side i can see my agent correctly goes to that link and then crosses but the enemy cannot do that because we only added one nav mesh link so if we go back to the nav mesh link and we just copy this component and paste it again and change the agent type to enemy one and then click play again the enemy will follow me across the jump but it doesn't look very good right they kind of just glide over kind of like they have really long legs and can just magically make it so how do we fix that in the navmesh components github repo unity provides us something called an agent link mover which gives us four different options for an agent to traverse a nav mesh link there's teleport parabola curve and normal speed normal speed behaves the exact same as we just saw so that's not really useful parabola will move the agent across a link in a parabola there's teleport which just teleports the navmesh agent from the start to end point immediately and then there's curve i think this is the most useful one because you can define a custom animation curve that defines the height of the navmesh agent as they traverse the nav mesh link that's the one we'll be using in this example the concept here is simple we get the off-mesh link data from the agent we find the start and end position and then we do a co-routine that evaluates the height position over the curve using vector3 lerp from the start and position and adding in the y offset from the curve it's very straightforward but this also provides us these other options that we might find useful later in our game i'll add the agent link mover to both the enemy and the player i'll set the method to be curve and define a simple parabolic curve if i click play again we'll see that both of the agents have a hop whenever they go over the nav mesh link it looks a lot better [Music] that's cool but we have all of these different heights what if we could have our player and enemy jump across the different heights i'll quickly adjust the size of this box and the position of the box to make it look like we can jump on top of these different balls [Music] then we'll just set up a couple nav mesh links to jump from the floor to on top of the box and then from on top of the box to on top of the wall so if we click play and i click on top of the box on the right side my player will actually run over there and jump on top of the box if i click on the other side exact same thing and if i click on top of the wall my player will go up there and there we have it the agents will jump across a hole they can jump to different heights and they have a different height curve instead of going in a straight line from wherever they are to wherever they're trying to go i hope you got a lot of value out of this video adding navmesh links allows you to make a lot more dynamic complex levels in your game if you have any comments suggestions or if you implemented this in your game drop a comment down below and you know it i'll see you on the next video you
Info
Channel: LlamAcademy
Views: 29,001
Rating: undefined out of 5
Keywords: Unity, Tutorial, How to unity, unity how to, llamacademy, navmeshlink, offmeshlink, ai jumping, unity ai, ai, navmesh, navmesh in unity, connecting navmeshes, jumping navmeshes, navmesh jump, unity navmesh, unity path finding, unity navigation, navmesh agent jump, navmeshagent jump, unity ai jump between platforms, unity ai jump, jump navmeshagent, unity navmeshagent jumping, connect navmesh, NavMesh link, nav mesh link, unity navmesh agent, unity navmeshagent, navmeshagent
Id: dpJUc_BpChw
Channel Id: undefined
Length: 8min 27sec (507 seconds)
Published: Tue Feb 16 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.