How to Show a Path to a Target | AI Series Part 31 | Unity Tutorial

Поділитися
Вставка
  • Опубліковано 10 вер 2024

КОМЕНТАРІ • 51

  • @K.Z007
    @K.Z007 10 місяців тому +2

    Whenever I want to add something new to my game, your channel is the top one to go to. You are amazing.

    • @LlamAcademy
      @LlamAcademy  10 місяців тому +1

      🧡 thank you! That made my day

  • @dustypants9326
    @dustypants9326 2 роки тому +2

    i didnt kno i needed this. I like the path to line renderer.
    In the past, i have spawned a "wisp" (particles + nav agent) to guide the player. But wisps were only good for hinting, and not all players follow hints.

    • @LlamAcademy
      @LlamAcademy  2 роки тому +2

      I bet you can get some cool effects with that approach too!

  • @ahmedsiddique2998
    @ahmedsiddique2998 Рік тому +1

    what about if our player is on height and the target is below your character i tried it goes through the ground cause navmesh is build on it

  • @klausbdl
    @klausbdl Рік тому

    if you're doing it with some kind of ai agent that the path can change while the coroutine is running, remember to update the NavMeshPath path INSIDE the while loop

  • @jhonuribe171
    @jhonuribe171 5 місяців тому

    I use this for a vehicle but I don't get the lines, I don't get an error and I don't know where I'm failing, I checked that everything was fine and the only difference is that you use a thirpesoncontroller and I don't

  • @alperaydin7011
    @alperaydin7011 2 роки тому +2

    Thanks

  • @intimidate2161
    @intimidate2161 Рік тому +1

    I was getting error on line 50. It was related to the line render path. I changed it to "Path" and its working now.

  • @swaranagatabose4782
    @swaranagatabose4782 6 місяців тому

    ActiveInstance = Instantiate(Prefab,
    Triangulation.vertices[Random.Range(0, Triangulation.vertices.Length)] + Vector3.up * SpawnHeightOffset,
    Quaternion.Euler(90, 0, 0)
    ); Comes an error in this line "index was outside the bounds of the array" please tell me how can i solve it?

  • @toborcomedy
    @toborcomedy Рік тому +1

    I don’t understand why this doesn’t even work when I download the source project file. Been trying for hours but I can’t get this line to show up! No errors, everything is linked just like the tutorial. Made sure to set everything. Ring is a collectible. Layers are good. Project settings physics are right

    • @LlamAcademy
      @LlamAcademy  Рік тому

      Hi 👋! I checked out the project from GitHub and just clicked play and it was working on 2019.4 LTS with Built In RP (same as I used in the video). Double check your LineRenderer settings to be sure it's enabled, has a material, and is hooked up to the "Path" property of the Collectable Spawner. It should work with URP no problem, but you'd have to do the material conversions

    • @toborcomedy
      @toborcomedy Рік тому +1

      @@LlamAcademy I appreciate you still commenting and trying to help even a year after! I downloaded the same unity version just to further try and replicate. Unfortunately I still cannot get this line to show up. Would you mind taking a look at this imgur i created? I just downloaded what you had and put together like the video and for the life of me can't find what's going wrong. imgur.com/a/iesI2ZX appreciate it thanks!

    • @LlamAcademy
      @LlamAcademy  Рік тому

      If you check “Use World Space” on that Line Renderer does it fix it for you? That’s one difference I spot here and we’re setting positions in world space so it might do it!
      Thanks for sending all those screenshots, it really helps understand what could be going on!

    • @toborcomedy
      @toborcomedy Рік тому +1

      @@LlamAcademy Just tested it out and still the indexoutofbounds:
      IndexOutOfRangeException: Index was outside the bounds of the array.
      CollectableSpawner.SpawnNewObject () (at Assets/Scripts/CollectableSpawner.cs:36)
      CollectableSpawner.Start () (at Assets/Scripts/CollectableSpawner.cs:31)
      I'll continue poking around trying to find fixes :(

    • @toborcomedy
      @toborcomedy Рік тому +1

      Triangulation.vertices has to be an empty array with 0 elements

  • @nileshkumawat2997
    @nileshkumawat2997 2 роки тому

    Hey you know about terrain Material? I am using curve world shader for game but this material when I use on terrain I can't able to paint texture on terrain but in normal default lit material we can paint texture.... So you know? What is problem in my shader material

    • @LlamAcademy
      @LlamAcademy  2 роки тому +1

      You have to have special shaders for terrains. Just a standard shader won’t work there. Your curved world shader probably is only for standard object rendering and doesn’t support terrain rendering.

  • @shepa9832
    @shepa9832 2 роки тому +1

    everything is cool, but brother, how did you add NavMesh Components in project? I don't see him in PackageManager...

    • @LlamAcademy
      @LlamAcademy  2 роки тому

      I added it by modifying the manifest.json. I describe how I add it in part 1: ua-cam.com/video/aHFSDcEQuzQ/v-deo.html

    • @shepa9832
      @shepa9832 2 роки тому +1

      @@LlamAcademy aa cool thanks)

  • @newbossbro3180
    @newbossbro3180 Рік тому

    Is there any room for improvement? Let's say calculating when the target position is on different polygon then recalculate, if its same then simply changing vector position

    • @LlamAcademy
      @LlamAcademy  Рік тому

      Yes of course there's room for improvement! I think it may be more computationally expensive to calculate which triangle the player is on from the NavMesh Triangulation than it would be to just calculate a new path though.

  • @t.t.9999
    @t.t.9999 2 роки тому

    57 lines of code doesnt work. why? Where else should I calculate the path?

    • @LlamAcademy
      @LlamAcademy  2 роки тому +1

      Sorry I'm not sure I understand the question. You can check out the repository on GitHub github.com/llamacademy/ai-series-part-31 and compare what you have to what I've done in the project.

  • @Strongest845
    @Strongest845 8 місяців тому

    is this possible to move objects along navmeshpath with rigidbody, not using navmeshagent ?

    • @LlamAcademy
      @LlamAcademy  8 місяців тому

      Yes, you can use NavMesh.CalculatePath() still to get a path, but I'm not sure what the use case is for using a Rigidbody if you're going to just follow the path.

    • @Strongest845
      @Strongest845 8 місяців тому

      @@LlamAcademy I want to do knockback effect, or jumping without offmeshlink, biggest example is risk of rain 2, where enemies can be knock up to the sky, something I am struggle with agent

    • @LlamAcademy
      @LlamAcademy  8 місяців тому +1

      @@Strongest845 hmm… stay tuned for next week’s video maybe that will help 😉

    • @Strongest845
      @Strongest845 8 місяців тому

      @@LlamAcademy i have made my rigidbody, or character controller kind of worked, i will get the move direction by get the path[1] - path[0], the problem rise at corner,it stand still at the corner, it maybe conflict by path[1] and path[0] too close at other, some time it stop frezze at corner and continue movement

  • @yours_indie_game_dev
    @yours_indie_game_dev Рік тому

    so if i spawn navemesh obstacles in runtime will i have to rebake the surface

    • @LlamAcademy
      @LlamAcademy  Рік тому

      Obstacles, no. Modifiers, yes.

    • @yours_indie_game_dev
      @yours_indie_game_dev Рік тому

      @@LlamAcademyi spawn some obstacles at runtime the line goesthrough them it only shows correctly when i rebake the navmesh

  • @MrSpherical_jr
    @MrSpherical_jr 2 роки тому +1

    is this possible in 2d game?

  • @michalbusik8621
    @michalbusik8621 10 місяців тому

    Hi, great tutorial, thank you. What do i need if i only want to draw path to the selected point? Without creating of new ring?

    • @LlamAcademy
      @LlamAcademy  10 місяців тому

      You can just remove the code related to spawning the ring and keep only the drawing the path portion and it will work just fine

    • @michalbusik8621
      @michalbusik8621 10 місяців тому

      @@LlamAcademy You mean the "SpawnNewObject" function? Anyway, i still have a problem with running the script. I have the same error as @3mmotion down in the coments. On the line wih Triangulation.Verticies in SpawnNewObject() it says that "Index is outside of the bounds of the array". I think it has somethign to do with navmesh because Trinagluation.Verticies has a value of 0 for some reason so than it cant calculate the path. I even tried it with your project from github and it does the same thing.

  • @dwikyanderson5039
    @dwikyanderson5039 2 роки тому

    the ActiveInstance is outside the bounds of array can someone help me

    • @LlamAcademy
      @LlamAcademy  2 роки тому

      Can you share the full error you're getting as well as what's not working? ActiveInstance is not an array so the error as you posted sounds like you may have some differences from what I have on the GitHub project: github.com/llamacademy/ai-series-part-31

  • @diegoguzman5717
    @diegoguzman5717 11 місяців тому +1

  • @neilfosteronly
    @neilfosteronly Рік тому

    Is the line always Agent Type Humanoid or first in the list? Any way to change what areas it can navigate? Thanks for these videos. You have the best tutorials for Unity right now.
    Edit: I see how it works now. NavMesh.AllAreas so it can walk everywhere.
    Here is what I used for the Line to only go on some areas.
    NavMesh.CalculatePath(Player.position, nearestOBJ.transform.position, NavMesh.GetAreaFromName("Road") | NavMesh.GetAreaFromName("Terrain"), path

    • @artinstroukeprod
      @artinstroukeprod 3 місяці тому

      I try to build a path solely on a specific zone like in your example and still the path is built on "Walkable" area... ((