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

Поделиться
HTML-код
  • Опубликовано: 4 янв 2025

Комментарии • 86

  • @unDeadGod69
    @unDeadGod69 Год назад +3

    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.

  • @tomoliverharrison
    @tomoliverharrison 3 года назад +13

    This channel deserves way more subs and views! Great tutorial and looking forward to getting through the whole series

  • @placebo_yue
    @placebo_yue 3 года назад +3

    the tip about the curve script was crucial! It makes an enormous difference. thank you

    • @LlamAcademy
      @LlamAcademy  3 года назад

      You're welcome! Glad it was helpful for you!

    • @hirasinghdhami4589
      @hirasinghdhami4589 3 года назад

      @@LlamAcademy IS there a direct link to the page, I need the code for the curve script and can't find it

    • @LlamAcademy
      @LlamAcademy  3 года назад

      @@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.

    • @MCWayet
      @MCWayet Месяц назад

      @@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

  • @maitrykotak3703
    @maitrykotak3703 8 месяцев назад +1

    following this channnel from.a long time,,,,its just awesome......very very helpful

  • @NunSuperior
    @NunSuperior 3 года назад +2

    I always wondered how off mesh links worked. Now I have them working. Awesome.

  • @AletseDev
    @AletseDev 2 года назад +1

    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.

  • @CrazyBabirussa
    @CrazyBabirussa 4 месяца назад +2

    After setting up Curve, it doesn't save the value. Please help.

  • @DaviSouzaGamer
    @DaviSouzaGamer Год назад +13

    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.

    • @lokeki8894
      @lokeki8894 Год назад +1

      thank you!

    • @timvandeneng4724
      @timvandeneng4724 10 месяцев назад +1

      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

  • @locusruizlopez5997
    @locusruizlopez5997 3 года назад +2

    I didnt know anything about nan mesh link, thanks :)

    • @LlamAcademy
      @LlamAcademy  3 года назад

      I'm glad to be able to help introduce you!

  • @munyunu
    @munyunu 3 года назад +2

    So so so useful and well-explained. Thanks so much.

  • @bujinkanatori
    @bujinkanatori 7 месяцев назад

    wonderful music, so calming

  • @rasheedqe
    @rasheedqe 3 года назад +1

    Great video that jumping component really helped.

  • @lukasvolcik5109
    @lukasvolcik5109 2 года назад +1

    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.

    • @LlamAcademy
      @LlamAcademy  2 года назад

      Awesome! Good luck with your RTS :) I've always wanted to make one but so far haven't gotten there

  • @paulberry3359
    @paulberry3359 2 года назад +1

    Another fantastic video!!

  • @ayuguplays2507
    @ayuguplays2507 2 года назад +1

    simply great video
    thanks for the tutorial. keep it up

  • @tianbornman6115
    @tianbornman6115 3 года назад +1

    wow exactly what i needed, thanks

  • @alextrollip7707
    @alextrollip7707 3 года назад +2

    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
      @LlamAcademy  3 года назад +1

      Glad it's helping! If there's a topic not covered you'd like to see, let me know!

    • @alextrollip7707
      @alextrollip7707 3 года назад +1

      @@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.

  • @友贤
    @友贤 7 месяцев назад

    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.

  • @LivingFigment
    @LivingFigment Год назад

    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!

    • @LlamAcademy
      @LlamAcademy  Год назад

      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.

    • @LivingFigment
      @LivingFigment Год назад

      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

  • @ty-xq7bl
    @ty-xq7bl Год назад

    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?

    • @LlamAcademy
      @LlamAcademy  Год назад

      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

  • @refinedturnip5296
    @refinedturnip5296 11 месяцев назад

    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

    • @LlamAcademy
      @LlamAcademy  11 месяцев назад +1

      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.

  • @CB66941
    @CB66941 Месяц назад

    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.

    • @LlamAcademy
      @LlamAcademy  Месяц назад +1

      I'm glad you figured it out. Great job!

  • @Ankh_Ramses
    @Ankh_Ramses 3 года назад +1

    Can you link the jumping to a blender aniumation, thanks.

    • @LlamAcademy
      @LlamAcademy  3 года назад

      In the next video in the series we do that! ruclips.net/video/wLZPM46zgUo/видео.html

  • @koolbro1960
    @koolbro1960 11 месяцев назад

    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?

    • @LlamAcademy
      @LlamAcademy  11 месяцев назад

      Hard to say just from the description. The teleportation sounds like the complete off mesh link didn’t get called

  • @ChadGatling
    @ChadGatling 2 года назад +1

    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.

    • @LlamAcademy
      @LlamAcademy  2 года назад

      Great! Glad you got it resolved so quickly!

  • @candycodes4575
    @candycodes4575 3 года назад +2

    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.

    • @LlamAcademy
      @LlamAcademy  3 года назад +1

      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

    • @candycodes4575
      @candycodes4575 3 года назад +1

      @@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.

    • @LlamAcademy
      @LlamAcademy  3 года назад

      @@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.

    • @candycodes4575
      @candycodes4575 3 года назад +1

      @@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?

    • @LlamAcademy
      @LlamAcademy  3 года назад

      @@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?

  • @mrpinkdev
    @mrpinkdev 2 года назад

    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

    • @LlamAcademy
      @LlamAcademy  2 года назад

      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

    • @creationsmaxo
      @creationsmaxo Год назад

      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.)

  • @kevinzawarrior
    @kevinzawarrior 2 года назад +1

    could I use the navmeshlink in a script for a leaping enemy im working on?

    • @LlamAcademy
      @LlamAcademy  2 года назад

      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

    • @kevinzawarrior
      @kevinzawarrior 2 года назад

      @@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
      @LlamAcademy  2 года назад

      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

    • @kevinzawarrior
      @kevinzawarrior 2 года назад

      @@LlamAcademy ok thank you!! I'll try it when I get home.

    • @kevinzawarrior
      @kevinzawarrior 2 года назад

      @@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

  • @InvisaPotion
    @InvisaPotion Год назад

    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.

    • @LlamAcademy
      @LlamAcademy  Год назад

      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.

  • @nileshkumawat6730
    @nileshkumawat6730 2 года назад

    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

    • @LlamAcademy
      @LlamAcademy  2 года назад

      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

    • @nileshkumawat6730
      @nileshkumawat6730 2 года назад

      @@LlamAcademy i thik this before your reply 😅 but not fully confident
      Thanks for telling this many many thanks

  • @claraca1138
    @claraca1138 2 года назад

    Can I jump but controlling my character with the keys and be able to fall if I jump wrong?

    • @LlamAcademy
      @LlamAcademy  2 года назад +1

      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

    • @claraca1138
      @claraca1138 2 года назад

      @@LlamAcademy Thanks, I´m Doing it like that, Because I started with NavMesh But I couldn´t do that. Thanks for helping me

  • @benmansourmahdi9097
    @benmansourmahdi9097 2 года назад

    i cannot find the navmesh component what do i do

    • @LlamAcademy
      @LlamAcademy  2 года назад +1

      Hi! How to install the NavMesh Components used in this video is described in Part 1: ruclips.net/video/aHFSDcEQuzQ/видео.html

  • @mana20
    @mana20 2 года назад

    Does this work with the newer AI pathfinding Unity has added?

    • @LlamAcademy
      @LlamAcademy  2 года назад +1

      This is using the Navigation Components. Ultimately the “new” and “old” are just different ways to interact with the same NavMesh system

    • @mana20
      @mana20 2 года назад

      @@LlamAcademy thanks for the clarification

  • @pattarawutsupattraphan804
    @pattarawutsupattraphan804 Год назад

    i have a question why my AI slides but doesn't jump like u

    • @LlamAcademy
      @LlamAcademy  Год назад

      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.

    • @oquangton5750
      @oquangton5750 6 месяцев назад +1

      Me too. I discovered that after setting up Curve, it doesn't save the value.

    • @CrazyBabirussa
      @CrazyBabirussa 4 месяца назад

      @@oquangton5750 me too

  • @coloneljcd6041
    @coloneljcd6041 2 года назад

    Is this whats now called OffMeshLink?

    • @LlamAcademy
      @LlamAcademy  2 года назад

      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

    • @coloneljcd6041
      @coloneljcd6041 2 года назад

      @@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