I recently finished your scriptable guns series and it helped me a lot in a project. Now I'm going to start with this AI series. Thanks for making this kind of content.
@@hirasinghdhami4589 Yes! It's on the github linked in the description: github.com/llamacademy/ai-series-part-2 - you can go to Assets and find the AgentLinkMover script in there.
@@LlamAcademy there seems to either be a NEW unity bug or the code broke from new unity updates as the curve isnt saved. Do you have any idea what might be the cause
The animation curve was resetting its value to an empty curve whenever the object was deselected. Removing the "m" prefix from the "m_Curve" field solved the problem for some reason.
oh my god i cannot emphasize this enough but THANK YOU! I was stuck on this f*cking problem for ages! almost broke my laptop in half to make it a fcking tablet because of this
Omg thankssss! ❤ exactly what I was looking for ❤ you're a lifesaver, I'm trying to build RTS where you can walk with your character inside of a newly built building.
It might be useful to in the intro show what we'd have at the end of the video. But it's pretty useful step by step guide so far. I've been reading through he documentation but videos are always less energy intensive to follow along with.
@@LlamAcademy I'm still watching through the playlist. But one thing I was struggling with was flying enemies(which is what made me find the playlist) But then also squad based movement. Having multiple units get selected when you select any of them(or drag select around all of them) And then having them move as a squad. Obviously with terrain they might have to be clumped(so obstacles avoidance doesn't work as an option) But when in open space I'd like them to sit in a formation sort of. And in doing so I could get them to move in various formations.
Is there a way to activate/disactivate a NavMeshLink when we need? right now the solution for me is to use a NavMeshObstacle to block either start point of end point.
Hi quick question - As you probably know, Unity's in-built autogenerated (not manual) off mesh links do not support bidirectionality for drop down links. And there doesn't seem to be a way to set them to be bidirectional via scripting. So with this new system, is there any support for "bidirectional auto generated navmesh links"? Would be fantastic if you could let me know, given this is a fairly new package and documentation is spotty. Thanks!
Hi! With Unity 2021 we have a 1.0.0-experimental release, and with Unity 2022 they actually have 1.1.1 version (not experimental) on the Package Manager. NavMeshLinks cannot be automatically generated. They must be manually placed, but can be bidirectional. The automatic OffMeshLink generation was really cool and nice. I hope in future releases they will add some form of auto-NavMeshLink generation.
That's what I thought. We need autogeneration *and* bidirectionality together to be added to the original offmesh links as well as the newer navmesh links. Thanks for the reply@@LlamAcademy
for procedural generated games involving navmeshes how would you implement a way to add these navmesh links? Would you just piece each prefab with a meshlink or do something more code driven which adds the mesh link params via code?
I cover procedural generation of levels in part 13-15. If you are spawning prefabs you can pre-attach the links. For more complex worlds you will have to come up with some algorithm to determine the spawn locations of the links and place them at runtime
Quick question regarding the RaycastNonAlloc. It seems to be way less accurate than the standard Raycast. For instance clicking on the top of the walls with the navmesh jump link, the ray is ignoring the wall and hitting the ground behind it sending my agent walking around the wall, wheras Raycast always hit the correct object and the agent jumps onto the wall. Could well be missing something really obvious as I'm fairly new Loving the series
Nope. You are right. For a case when you want only the first option a standard Raycast is a better option. When we want multiple hits, RaycastNonAlloc is a better option than RaycastAll because it does not generate garbage.
The animation curve works, but it feels difficult to get right. My player and enemy seem to teleport to the ground during the end of the curve. I downloaded your project and it doesn't have that problem. Is it the way the navmeshlink is setup? EDIT: Ok, I think I figured out why, though who knows if that may change in the next tutorial. The scale of your player or enemy game object will affect how the jump looks, so make sure to set the scale correctly. It worked fine when I set the Y scale to 1.
When using the AgentLinkMover, my agent jumps across to the end point, then jumps back and then teleports back to the start, any thoughts on how to fix this?
I can't get this to work. It's just doing nothing. I have 2 objects with nave meshes and an object with a link and the ends are on the different meshes but the connecting lines are dull and agents ignore the other nav mesh. Edit: Got it. The little circles indicating that the link was on the mesh were very small and I was not noticing that they were not activated.
Another nice tutorial. :D Keep it up man! I 'm just following along :D Although I think AgentLinkMover is a bit buggy right now. It no longer works if I disable then enable my object(any object the component is attached - player or enemy). So I opted not to use it.
Wow! Great catch! I can't believe I haven't noticed that! AgentLinkMover was directly taken from the NavMeshComponents repo and is classified as an EXAMPLE script (meaning, probably has some issues). To specifically resolve what you've mentioned here, you can do the following: Rename IEnumerator Start() to IEnumerator CheckForLink() add a private Coroutine CheckLinkCoroutine; Add a void OnEnable() { if (CheckLinkCoroutine != null) { StopCoroutine(CheckLinkCoroutine); } CheckLinkCoroutine = StartCoroutine(CheckForLink()); } and that should make it so your pooled or enabled/disabled agents can still traverse the link
@@LlamAcademy Hi, I can seem to understand a bit what you did there. One question, why rename Start? It works just the same, with Start. is it to avoid confusion with the monobehaviour default Start method? Just wanted to know your reasoning, as tiny insights like this might help me code better in the future.
@@candycodes4575 Of course! Removing the code from the "Start" function to a Coroutine we can manage allows us to explicitly start and stop the coroutine when the GameObject is enabled in OnEnable. We also stop any dangling coroutines that are running.
@@LlamAcademy Ah yes, I meant when your doing the CheckLinkCoroutine = StartCoroutine(CheckForLink()); You can do the same thing without renaming Start like so CheckLinkCoroutine = StartCoroutine(Start()); I was wondering if you had any specific reason as to why you renamed Start to CheckForLink?
@@candycodes4575 Unity will automatically start a Coroutine for Start if you make it return IEnumerator and you have no visibility into if it's running or not. By renaming the function and controlling it from within the MonoBehaviour OnEnable, you know exactly what's happening and can control the Coroutine. Does that make more sense?
Is there a way to set up navmesh links on procedural levels? I use marching cubes voxels for generating levels and then bake navmeshes in runtime which seems to be not ideal
Yes, you can position a NavMeshLink at runtime and it will be considered by the NavMesh. For procedural levels, you may want to bake only the area around the player for better performance. You can start here for more info on that: ruclips.net/video/RuoK7w1OIT0/видео.html
Since Unity 2021, there's a component to generate/update a NavMesh dynamically in a scene called "NavMeshSurface". It's basically the same kind of menu as the Navigation menu for a regular NavMesh's baking setup, but it's a component, hence you can access it during gameplay and call BuildNavMesh(); on that component to update your NavMesh in real-time. A warning about the NavMeshSurface is that its default settings are not properly set and can put a massive toll on performances if you don't set it right depending on the size and complexity of the NavMesh being generated during gameplay. For example, the default setting for "Use Geometry" is "Render Meshes" which means that the NavMesh will be generated based on every rendered mesh in the included layers regardless if they have/need physics or not. Changing it to "Physics Colliders" allows you to make sure it only check existing colliders to generate the NavMesh and leave anything else alone. It's the same with the included layers which ,by default, is "Everything". Creating a layer specifically for stuff for your NavMesh to be based on (like a layer called "Ground") can save a LOT on performances. You can also use the NavMeshSurface to bake and generate independent Nav Mesh Data files ahead. If you can't seem to find the NavMeshSurface in the components, you got to make sure you have the "AI Navigation" package of at least version 1.0.0rev4 installed in your project. (Currently as I'm typing this, it's a v1.1.1.)
NavMeshLink isn’t the right tool for that job. For a leaping enemy you can take a look at AI Series Part 21 where I show how to implement a leaping enemy ruclips.net/video/faNV-hWu07o/видео.html
@@LlamAcademy thank you i will, but i have one question, would it be able to work with setdestination() ? i want him to naturally leap around the map while following the player.
@@LlamAcademy I looked into it a bit and the off mesh movement looks like it would be used for a more stationary climb (like a preset wall in a level) Should I make it leap to the end position then reset the start position to the end position? And if so how would I get the direction it needs to go without the player being observable? or should I some how make the enemy jump/float(my current issue) while following the player with the agent enabled
Is there any way to stop the enemy from accidentally touching the nav mesh link and getting jumped accross? Also when this happens the enemy will teleport to you after the jump.
Yes, you can check the end point of the OffMeshLink in the AgentLinkMover and see if that is actually taking you in the direction of your current path. If not, I believe you can call CompleteOffMeshLink() without consequence.
Hard to say just from that. Sometimes with wide NavMeshLinks the agent traverses the link in a strange way. I typically keep the links with a width of 1 or less
That's not a great use case for using the NavMesh. Instead, I'd recommend using a Rigidbody physics controller for your player for that kind of behavior
OffMeshLink is what it’s called by the Navigation system. The new NavMesh Components provide a high level component called the NavMeshLink that under the hood creates an OffMeshLink
I recently finished your scriptable guns series and it helped me a lot in a project. Now I'm going to start with this AI series. Thanks for making this kind of content.
This channel deserves way more subs and views! Great tutorial and looking forward to getting through the whole series
Much appreciated!
the tip about the curve script was crucial! It makes an enormous difference. thank you
You're welcome! Glad it was helpful for you!
@@LlamAcademy IS there a direct link to the page, I need the code for the curve script and can't find it
@@hirasinghdhami4589 Yes! It's on the github linked in the description: github.com/llamacademy/ai-series-part-2 - you can go to Assets and find the AgentLinkMover script in there.
@@LlamAcademy there seems to either be a NEW unity bug or the code broke from new unity updates as the curve isnt saved. Do you have any idea what might be the cause
following this channnel from.a long time,,,,its just awesome......very very helpful
I always wondered how off mesh links worked. Now I have them working. Awesome.
Wonderful! 🙌
I think the AI is the most difficult part of making an video-game for me, and this channel saves my life. I thank you a lot, u are amazing.
After setting up Curve, it doesn't save the value. Please help.
The animation curve was resetting its value to an empty curve whenever the object was deselected. Removing the "m" prefix from the "m_Curve" field solved the problem for some reason.
thank you!
oh my god i cannot emphasize this enough but THANK YOU! I was stuck on this f*cking problem for ages! almost broke my laptop in half to make it a fcking tablet because of this
I didnt know anything about nan mesh link, thanks :)
I'm glad to be able to help introduce you!
So so so useful and well-explained. Thanks so much.
You're welcome!
wonderful music, so calming
Great video that jumping component really helped.
Thank you!
Omg thankssss! ❤ exactly what I was looking for ❤ you're a lifesaver, I'm trying to build RTS where you can walk with your character inside of a newly built building.
Awesome! Good luck with your RTS :) I've always wanted to make one but so far haven't gotten there
Another fantastic video!!
simply great video
thanks for the tutorial. keep it up
Thank you 🤗
wow exactly what i needed, thanks
Great to hear!
It might be useful to in the intro show what we'd have at the end of the video.
But it's pretty useful step by step guide so far.
I've been reading through he documentation but videos are always less energy intensive to follow along with.
Glad it's helping! If there's a topic not covered you'd like to see, let me know!
@@LlamAcademy I'm still watching through the playlist.
But one thing I was struggling with was flying enemies(which is what made me find the playlist)
But then also squad based movement.
Having multiple units get selected when you select any of them(or drag select around all of them)
And then having them move as a squad.
Obviously with terrain they might have to be clumped(so obstacles avoidance doesn't work as an option)
But when in open space I'd like them to sit in a formation sort of.
And in doing so I could get them to move in various formations.
Is there a way to activate/disactivate a NavMeshLink when we need? right now the solution for me is to use a NavMeshObstacle to block either start point of end point.
Hi quick question - As you probably know, Unity's in-built autogenerated (not manual) off mesh links do not support bidirectionality for drop down links. And there doesn't seem to be a way to set them to be bidirectional via scripting. So with this new system, is there any support for "bidirectional auto generated navmesh links"? Would be fantastic if you could let me know, given this is a fairly new package and documentation is spotty. Thanks!
Hi! With Unity 2021 we have a 1.0.0-experimental release, and with Unity 2022 they actually have 1.1.1 version (not experimental) on the Package Manager.
NavMeshLinks cannot be automatically generated. They must be manually placed, but can be bidirectional. The automatic OffMeshLink generation was really cool and nice. I hope in future releases they will add some form of auto-NavMeshLink generation.
That's what I thought. We need autogeneration *and* bidirectionality together to be added to the original offmesh links as well as the newer navmesh links. Thanks for the reply@@LlamAcademy
for procedural generated games involving navmeshes how would you implement a way to add these navmesh links? Would you just piece each prefab with a meshlink or do something more code driven which adds the mesh link params via code?
I cover procedural generation of levels in part 13-15. If you are spawning prefabs you can pre-attach the links. For more complex worlds you will have to come up with some algorithm to determine the spawn locations of the links and place them at runtime
Quick question regarding the RaycastNonAlloc.
It seems to be way less accurate than the standard Raycast. For instance clicking on the top of the walls with the navmesh jump link, the ray is ignoring the wall and hitting the ground behind it sending my agent walking around the wall, wheras Raycast always hit the correct object and the agent jumps onto the wall.
Could well be missing something really obvious as I'm fairly new
Loving the series
Nope. You are right. For a case when you want only the first option a standard Raycast is a better option. When we want multiple hits, RaycastNonAlloc is a better option than RaycastAll because it does not generate garbage.
The animation curve works, but it feels difficult to get right. My player and enemy seem to teleport to the ground during the end of the curve. I downloaded your project and it doesn't have that problem. Is it the way the navmeshlink is setup?
EDIT:
Ok, I think I figured out why, though who knows if that may change in the next tutorial. The scale of your player or enemy game object will affect how the jump looks, so make sure to set the scale correctly. It worked fine when I set the Y scale to 1.
I'm glad you figured it out. Great job!
Can you link the jumping to a blender aniumation, thanks.
In the next video in the series we do that! ruclips.net/video/wLZPM46zgUo/видео.html
When using the AgentLinkMover, my agent jumps across to the end point, then jumps back and then teleports back to the start, any thoughts on how to fix this?
Hard to say just from the description. The teleportation sounds like the complete off mesh link didn’t get called
I can't get this to work. It's just doing nothing. I have 2 objects with nave meshes and an object with a link and the ends are on the different meshes but the connecting lines are dull and agents ignore the other nav mesh.
Edit: Got it. The little circles indicating that the link was on the mesh were very small and I was not noticing that they were not activated.
Great! Glad you got it resolved so quickly!
Another nice tutorial. :D
Keep it up man! I 'm just following along :D
Although I think AgentLinkMover is a bit buggy right now. It no longer works if I disable then enable my object(any object the component is attached - player or enemy). So I opted not to use it.
Wow! Great catch! I can't believe I haven't noticed that!
AgentLinkMover was directly taken from the NavMeshComponents repo and is classified as an EXAMPLE script (meaning, probably has some issues).
To specifically resolve what you've mentioned here, you can do the following:
Rename IEnumerator Start() to IEnumerator CheckForLink()
add a private Coroutine CheckLinkCoroutine;
Add a void OnEnable() {
if (CheckLinkCoroutine != null) {
StopCoroutine(CheckLinkCoroutine);
}
CheckLinkCoroutine = StartCoroutine(CheckForLink());
}
and that should make it so your pooled or enabled/disabled agents can still traverse the link
@@LlamAcademy Hi, I can seem to understand a bit what you did there.
One question, why rename Start?
It works just the same, with Start.
is it to avoid confusion with the monobehaviour default Start method?
Just wanted to know your reasoning, as tiny insights like this might help me code better in the future.
@@candycodes4575 Of course! Removing the code from the "Start" function to a Coroutine we can manage allows us to explicitly start and stop the coroutine when the GameObject is enabled in OnEnable. We also stop any dangling coroutines that are running.
@@LlamAcademy
Ah yes, I meant when your doing the
CheckLinkCoroutine = StartCoroutine(CheckForLink());
You can do the same thing without renaming Start like so
CheckLinkCoroutine = StartCoroutine(Start());
I was wondering if you had any specific reason as to why you renamed Start to CheckForLink?
@@candycodes4575 Unity will automatically start a Coroutine for Start if you make it return IEnumerator and you have no visibility into if it's running or not. By renaming the function and controlling it from within the MonoBehaviour OnEnable, you know exactly what's happening and can control the Coroutine. Does that make more sense?
Is there a way to set up navmesh links on procedural levels? I use marching cubes voxels for generating levels and then bake navmeshes in runtime which seems to be not ideal
Yes, you can position a NavMeshLink at runtime and it will be considered by the NavMesh.
For procedural levels, you may want to bake only the area around the player for better performance. You can start here for more info on that: ruclips.net/video/RuoK7w1OIT0/видео.html
Since Unity 2021, there's a component to generate/update a NavMesh dynamically in a scene called "NavMeshSurface".
It's basically the same kind of menu as the Navigation menu for a regular NavMesh's baking setup, but it's a component, hence you can access it during gameplay and call BuildNavMesh(); on that component to update your NavMesh in real-time.
A warning about the NavMeshSurface is that its default settings are not properly set and can put a massive toll on performances if you don't set it right depending on the size and complexity of the NavMesh being generated during gameplay. For example, the default setting for "Use Geometry" is "Render Meshes" which means that the NavMesh will be generated based on every rendered mesh in the included layers regardless if they have/need physics or not. Changing it to "Physics Colliders" allows you to make sure it only check existing colliders to generate the NavMesh and leave anything else alone. It's the same with the included layers which ,by default, is "Everything". Creating a layer specifically for stuff for your NavMesh to be based on (like a layer called "Ground") can save a LOT on performances.
You can also use the NavMeshSurface to bake and generate independent Nav Mesh Data files ahead.
If you can't seem to find the NavMeshSurface in the components, you got to make sure you have the "AI Navigation" package of at least version 1.0.0rev4 installed in your project. (Currently as I'm typing this, it's a v1.1.1.)
could I use the navmeshlink in a script for a leaping enemy im working on?
NavMeshLink isn’t the right tool for that job. For a leaping enemy you can take a look at AI Series Part 21 where I show how to implement a leaping enemy ruclips.net/video/faNV-hWu07o/видео.html
@@LlamAcademy thank you i will, but i have one question, would it be able to work with
setdestination() ? i want him to naturally leap around the map while following the player.
Yup! You’ll have to play with the off-mesh movement to get a natural result, but you’ll learn the pattern to apply over there
@@LlamAcademy ok thank you!! I'll try it when I get home.
@@LlamAcademy I looked into it a bit and the off mesh movement looks like it would be used for a more stationary climb (like a preset wall in a level)
Should I make it leap to the end position then reset the start position to the end position? And if so how would I get the direction it needs to go without the player being observable?
or should I some how make the enemy jump/float(my current issue) while following the player with the agent enabled
Is there any way to stop the enemy from accidentally touching the nav mesh link and getting jumped accross? Also when this happens the enemy will teleport to you after the jump.
Yes, you can check the end point of the OffMeshLink in the AgentLinkMover and see if that is actually taking you in the direction of your current path. If not, I believe you can call CompleteOffMeshLink() without consequence.
Hey i am using navmesh link when agent take navmesh link that time gitch happen agent going random pos for sometime instead of go to player pos
Hard to say just from that. Sometimes with wide NavMeshLinks the agent traverses the link in a strange way. I typically keep the links with a width of 1 or less
@@LlamAcademy i thik this before your reply 😅 but not fully confident
Thanks for telling this many many thanks
Can I jump but controlling my character with the keys and be able to fall if I jump wrong?
That's not a great use case for using the NavMesh. Instead, I'd recommend using a Rigidbody physics controller for your player for that kind of behavior
@@LlamAcademy Thanks, I´m Doing it like that, Because I started with NavMesh But I couldn´t do that. Thanks for helping me
i cannot find the navmesh component what do i do
Hi! How to install the NavMesh Components used in this video is described in Part 1: ruclips.net/video/aHFSDcEQuzQ/видео.html
Does this work with the newer AI pathfinding Unity has added?
This is using the Navigation Components. Ultimately the “new” and “old” are just different ways to interact with the same NavMesh system
@@LlamAcademy thanks for the clarification
i have a question why my AI slides but doesn't jump like u
Did you add in the NavMeshLinkMover and make sure it's set up like what we did here? The default behavior is to just slide.
Me too. I discovered that after setting up Curve, it doesn't save the value.
@@oquangton5750 me too
Is this whats now called OffMeshLink?
OffMeshLink is what it’s called by the Navigation system. The new NavMesh Components provide a high level component called the NavMeshLink that under the hood creates an OffMeshLink
@@LlamAcademy Ah ok I am using an OffMeshLink now, but it doesnt have the Width field like the other on has. So thats why, Ok Thanks