2D NavMesh | 2D Pathfinding | Unity Game Engine (Simple & Easy)

- How to create 2D AI pathfinding using the Unity NavMesh components!
- How to have 2D NavMesh Agent in Unity 2022!
GitHub Link: github.com/h8man/NavMeshPlus
And don't forget to subscribe for more! ;)

Пікірлер: 107

  • @rootbindev
    @rootbindev Жыл бұрын

    Nice tutorial i like it! There are some updates so following this wont work 100%, I've created a new tutorial on my channel to follow along 2023 for this.

  • @theworldofgamedesign3078

    @theworldofgamedesign3078

    Жыл бұрын

    Appreciate the help, I’ll pin your comment.

  • @gameken350
    @gameken350 Жыл бұрын

    It was the most easy-to-understand explanation of the videos and sites I've seen so far.

  • @MayDicGaming
    @MayDicGaming Жыл бұрын

    For anyone who can't find "NavMesh Surface2d", this is the new way from repo. 1.add navigation surface 2.add navmesh collectSoures2d

  • @theworldofgamedesign3078

    @theworldofgamedesign3078

    Жыл бұрын

    Thank you

  • @yanbatista2828

    @yanbatista2828

    Жыл бұрын

    thaaaank youu!!!!!!!!!

  • @Ziplock9000

    @Ziplock9000

    Жыл бұрын

    Even the repo itself in June 2023 still refers to Surface2d. Thanks

  • @user-eo5kk1sh3e

    @user-eo5kk1sh3e

    4 ай бұрын

    But it doesn't work

  • @alexsolovyov3322
    @alexsolovyov3322 Жыл бұрын

    Hey man, thank you for making this video! I was just looking for the way to set up basic 2D pathfinding in my game.

  • @theworldofgamedesign3078

    @theworldofgamedesign3078

    Жыл бұрын

    My pleasure :)

  • @tienvantheten8924
    @tienvantheten8924 Жыл бұрын

    7 hours of trying to make an AI with pathfinding, meanwhile this video makes it so much quicker ty ty

  • @darkwolf811
    @darkwolf8114 ай бұрын

    Thanks! Really helpful. I will add that if your world scale is too small, the nav mesh agent will have some difficulties moving sometimes.

  • @baazarafa
    @baazarafa6 ай бұрын

    Incredible tutorial, no BS or intro just straight to the point.

  • @theworldofgamedesign3078

    @theworldofgamedesign3078

    6 ай бұрын

    Exactly, because how much I struggled with those entries, I decided that I will never do that in my videos.

  • @f.ingenia
    @f.ingenia Жыл бұрын

    Thanks! It is short and useful! You saved my time.

  • @theworldofgamedesign3078

    @theworldofgamedesign3078

    Жыл бұрын

    Glad to hear that!

  • @loneman1288
    @loneman1288 Жыл бұрын

    You have resqued me! Thank You! OMG It's working!

  • @user-mq8ss2sf1j
    @user-mq8ss2sf1j Жыл бұрын

    感谢你的视频,也感谢navmeshplus的作者,看完视频两个小时就完成了我的导航系统😘😘

  • @theworldofgamedesign3078

    @theworldofgamedesign3078

    Жыл бұрын

    太棒了,很高兴听到这个消息

  • @GamingBotanist
    @GamingBotanist Жыл бұрын

    For anyone running into problems with their mesh agents getting caught on corners: your box colliders are probably the culprit. Switch them to circle colliders (worked for me, easier) or disable the collider when you agent gets stuck (what I did initially).

  • @theworldofgamedesign3078

    @theworldofgamedesign3078

    Жыл бұрын

    Thanks for the tip! I pinned your comment.

  • @radiance8940
    @radiance8940 Жыл бұрын

    for anyone not finding the 2D option, they changed some things and its explaned well in the repo. it should still work

  • @theworldofgamedesign3078

    @theworldofgamedesign3078

    Жыл бұрын

    Thanks for the heads up

  • @Ziplock9000

    @Ziplock9000

    Жыл бұрын

    Actually the repo still refers to the Surface 2D.

  • @Darthrein
    @Darthrein11 ай бұрын

    Very informative and usefull tutorial. Thanks.

  • @jfblm
    @jfblm8 ай бұрын

    This tutorial is a miracle in my life. Might save my Game Thesis.

  • @theworldofgamedesign3078

    @theworldofgamedesign3078

    8 ай бұрын

    Glad I could help :)

  • @redriver9298
    @redriver929811 ай бұрын

    Hello, there was a problem when the character should move along the Y axis by a negative value, a glitch occurs and the character seems to get stuck halfway

  • @joe2249
    @joe224911 ай бұрын

    If anyone is having trouble with their Sprite not appearing on screen after following the steps: Make sure to add: agent.updateRotation = false; agent.updateUpAxis = false; I didn't add this to my enemy AI and my sprite didn't appear because the NavMeshAgent component was meant for 3D objects.

  • @3k_honne

    @3k_honne

    Ай бұрын

    WTF, Thank you!!!!!

  • @user-ck3jz8os7q
    @user-ck3jz8os7q7 ай бұрын

    Hello, I have a question. Navmesh Agents will over ride colliders that were not baked. They will literally walk through walls when they have a destination. Have you encountered this problem? How do I fix it?

  • @JansenJaspion
    @JansenJaspion6 ай бұрын

    Can't make it work on tiled sprites. Did someone made it work with tiled sprites?

  • @sebastiansanhueza9601
    @sebastiansanhueza9601 Жыл бұрын

    Thanks for this! It's super clear and concise. I wonder whether I could ask for your help with something. I've been trying NavMesh and A* for the last couple of weeks, and only now I've managed to make NavMesh work the way you show it. I've realized that the problem seemed to be the size of my pixel objects. I'm working with 3-pixel-thick walls or 16-pixel-high characters. When I do that, no coherent NavMesh bakes when I press Bake. I'm tempted to think that the pixel-objects are too small for them to register when baking the mesh - but all of this is conjecture, as I'm really a newbie on Unity. Do you know how I could bake the mesh with smaller objects, or at least why I would have the described problem? Once again, thanks for the tutorial, mate!

  • @theworldofgamedesign3078

    @theworldofgamedesign3078

    Жыл бұрын

    Thanks for the comment! Glad you found this beneficial, for the issue you’re coming across, I remember having such thing before, but unfortunately I don’t remember the exact solution, but if I’m not wrong, it could be fixed from one of the pixel’s components/options, try changing the scale, rotation, or the shape, and see if you find a solution in that, if the problem presents, write back and I’ll try to look into it.

  • @MagnusRazer
    @MagnusRazer4 ай бұрын

    Suppose you have a grid (it could be a TileMap2D) where the rule is that crossing diagonally has a cost of "3" and sides "2", plus your enemy has a maximum movement of "10". How to do it?

  • @nikitavuevski4756
    @nikitavuevski47565 ай бұрын

    I dont see a NavMeshSurface2d? Am I doing something worng..

  • @vickrpg
    @vickrpg Жыл бұрын

    Pressing Bake doesn't seem to do anything for me. The navmesh doesnt show. It takes a second to calculate but nothing changes.

  • @wendellfranco2259

    @wendellfranco2259

    Жыл бұрын

    me too, the mesh do not appears

  • @nachohotdawg5634

    @nachohotdawg5634

    Жыл бұрын

    R u using grid for the ground?

  • @TheOfficiaITristam
    @TheOfficiaITristam Жыл бұрын

    this doesnt work in version 2019.4

  • @RasikaChandle
    @RasikaChandle Жыл бұрын

    How can the radius of the mesh be altered? I want it to match the graphics, currently the mesh goes far away from the grpahics.

  • @theworldofgamedesign3078

    @theworldofgamedesign3078

    Жыл бұрын

    U mean the collider? If so you can make an empty game object with a circle collider then add your object to it

  • @Bordex
    @Bordex Жыл бұрын

    How can i calculate and draw path from object to target with this ? PLEASE ANSWER IM DESPERATE

  • @theworldofgamedesign3078

    @theworldofgamedesign3078

    Жыл бұрын

    Check this out it’s generated by ChatGPT: using UnityEngine; public class LineDrawer : MonoBehaviour { public Transform objectTransform; public Transform targetTransform; void Update() { Vector2 objectPosition = objectTransform.position; Vector2 targetPosition = targetTransform.position; Debug.DrawLine(objectPosition, targetPosition, Color.red); } } This script uses the Debug.DrawLine() method to draw a line in the scene view. The line will be drawn from the position of the objectTransform to the position of the targetTransform. You can assign these transforms in the Unity editor by dragging the corresponding objects into the fields in the inspector. The color of the line is set to red in this example, but you can change it to any other color. This script assumes that the GameObjects are 2D and the position is Vector2, if it's 3D you need to use Vector3 instead and change the method to Debug.DrawLine(objectPosition, targetPosition, Color.red,float duration);

  • @Etienne.780
    @Etienne.780 Жыл бұрын

    I have a question can you onley use tilemaps ? or is there a way so that I could use other gameobjects

  • @theworldofgamedesign3078

    @theworldofgamedesign3078

    Жыл бұрын

    I think for this specific package you would need a tilemap

  • @alfonzo1
    @alfonzo15 ай бұрын

    not working nothing happens when baked

  • @lebkete
    @lebkete Жыл бұрын

    Hey, I need help. My mesh agents getting caught on corners. So I try Switch them to circle colliders. But I don't have no idea What do you mean circle colliders?

  • @theworldofgamedesign3078

    @theworldofgamedesign3078

    Жыл бұрын

    Circle collider is a component you can add to your object, so remove the box collider and add a circle collider instead, that might solve the issue

  • @jakegordon1575
    @jakegordon1575 Жыл бұрын

    There isn't any 'navmesh agent' component when i try to add it to my actor EDIT: you have to import the navigation package for that component actually, it isn't included in the 2D core project

  • @theworldofgamedesign3078

    @theworldofgamedesign3078

    Жыл бұрын

    Thank you for clarification

  • @JustATortoise
    @JustATortoise Жыл бұрын

    Why does it say "This component will be removed in future releases, use NavMeshExtensions instead."

  • @SpirityLandia

    @SpirityLandia

    Жыл бұрын

    NavMeshExtensions not exists here :(

  • @TienPham-kl7tf
    @TienPham-kl7tf Жыл бұрын

    Yesterday I struggled myself with this NavMesh, I installed different version (the newest version) called AI Navigation. No matter what I did, it didn't work, cannot bake and no sign of any blue overlay. Apparently, it could only bake on 3D, but not on 2D. Thanks for the video, it solved my headache.

  • @theworldofgamedesign3078

    @theworldofgamedesign3078

    Жыл бұрын

    Glad I could help

  • @dragoonian385
    @dragoonian385 Жыл бұрын

    The component "NavMesh Surface2d isnt appearing in the package (nor is it appearing on the github) do you know if it was replaced by anything)

  • @theworldofgamedesign3078

    @theworldofgamedesign3078

    Жыл бұрын

    No not really, I’ve pinned a comment today, check it out.

  • @kryuza3191

    @kryuza3191

    Жыл бұрын

    @@theworldofgamedesign3078 I don't see the pinned comment and im having troubles because navmesh surface2d isn't appearing to mine as well

  • @nachohotdawg5634

    @nachohotdawg5634

    Жыл бұрын

    It could be due to a different Unity version

  • @thetruemystic_
    @thetruemystic_ Жыл бұрын

    it seems my sprite is getting rotated to -90 on the x direction, even though the agent remains the correct way up. Any ideas? The sprite also doesn't follow the agent, even though the component is on the same object as the agent itself

  • @tnznfla1223

    @tnznfla1223

    Жыл бұрын

    add this to your agent object > agent.updateRotation = false;

  • @Ziplock9000

    @Ziplock9000

    Жыл бұрын

    Same issue.

  • @user-gn6qp9hu2l

    @user-gn6qp9hu2l

    Жыл бұрын

    Did you manage to fix the issue?

  • @thetruemystic_

    @thetruemystic_

    Жыл бұрын

    @@user-gn6qp9hu2l we did, although I'm not 100 percent sure on what that fix was now - it might have just been running thru the video again from the start and then it worked but not sure

  • @leandropistelli4099
    @leandropistelli4099 Жыл бұрын

    please, can you help me? I'm trying to use Navmesh surface 2D but its missing :c

  • @theworldofgamedesign3078

    @theworldofgamedesign3078

    Жыл бұрын

    Try same version in the video

  • @rockstargaming7605
    @rockstargaming7605 Жыл бұрын

    how do you make this work for 2D Side-Scroller game ?

  • @theworldofgamedesign3078

    @theworldofgamedesign3078

    Жыл бұрын

    Perhaps by constraining Y movement in the rigidbody

  • @andersonkaueplebani5581
    @andersonkaueplebani5581 Жыл бұрын

    Nice tutorial. Unfortunately, I cant make it work (Unity.2022.2.7f1). Right after importing the package (Package Manager > Add package from disk...), it throws a lot of LogWarnings identifying some obsolete codes. I can ignore that. But when continuing your tutorial, it simply doesnt bake the Navmesh. Maybe the package must be updated, I dont know.

  • @andersonkaueplebani5581

    @andersonkaueplebani5581

    Жыл бұрын

    I guess I found a solution. Instead of using NavMeshModifier and NavMeshSurface2d components when you use it in your tutorial, I used Navigation Modifier and Navigation Surface components. The rest is exactly the same. I dont know if it will cause problems in the future, but with this workaround I was able to finish the tutorial with the same result. Note: using Unity 2022.2.7f1.

  • @theworldofgamedesign3078

    @theworldofgamedesign3078

    Жыл бұрын

    Good to hear!!

  • @mohammadumarsajid8214

    @mohammadumarsajid8214

    Жыл бұрын

    @@andersonkaueplebani5581 ​ after seeing all the comments for my solution, Thank God i didnt skipped your comment, it worked for me

  • @nileshkumawat6730
    @nileshkumawat6730 Жыл бұрын

    This is use for commercial and non commercial? Anywhere Or more question A* pathfinding better than this ?

  • @luanmartinssilva1239

    @luanmartinssilva1239

    Жыл бұрын

    Nice vídeo ! In my project, NavMeshAgent and Navigation Windown are missing. Have a solution for this ?

  • @mustafahuseynov4801

    @mustafahuseynov4801

    Жыл бұрын

    Have you figured this out? I am actually also thinking about implementing A* Algorithm, but solution in video seems much easier. What did you do?

  • @gbezjak
    @gbezjak Жыл бұрын

    This is awesome. Thanks! Is there a way to face an agent in the direction of moving?

  • @theworldofgamedesign3078

    @theworldofgamedesign3078

    Жыл бұрын

    Thank you, this could be made from the script, having a function that rotates the agent towards the moving direction.

  • @gbezjak

    @gbezjak

    Жыл бұрын

    ​@@theworldofgamedesign3078 And how can I know what is the moving direction? Sorry but I am a junior and I am working on a game just by myself. I've made a child object as a pivot point which I named rotator (the rotator has another child with a sprite that serves as a sight cone), so it's not the agent that rotates but the child rotator. My thoughts were to compare two vector2 variables - the current position of the agent and the last, and if there is a difference, the rotator rotates to that direction, but I'm lost with mathf and quaternions. :D

  • @gbezjak

    @gbezjak

    Жыл бұрын

    If somebody has or will have the same problem, I've come up with the solution. In the agent script: agent.SetDestination(target); velocity = agent.velocity; //which is a Vector2 variable In the child rotator script: Quaternion toRotation = Quaternion.LookRotation( agent transform.forward, agent velocity); transform.rotation = Quaternion.RotateTowards(transfform.rotation, toRotation, rotationSpeed * Time.deltaTime);

  • @TienPham-kl7tf
    @TienPham-kl7tf Жыл бұрын

    for some reason, Object having NavMesh Agent disappear in Game Scene, to anyone that have the same problem as I did, set "base offset" in NavMesh Agent to 0.

  • @theworldofgamedesign3078

    @theworldofgamedesign3078

    Жыл бұрын

    Thanks for the clarification

  • @mohammadumarsajid8214

    @mohammadumarsajid8214

    Жыл бұрын

    still cant see bro

  • @skave7228
    @skave7228 Жыл бұрын

    Nothing happen when I click Bake, do you have any Idea what I could have messed up ?

  • @nachohotdawg5634

    @nachohotdawg5634

    Жыл бұрын

    Grid used for the ground?

  • @skave7228

    @skave7228

    Жыл бұрын

    @@nachohotdawg5634 Yup

  • @Account95555
    @Account95555 Жыл бұрын

    Thank you, I just had to change a few things because it updated but it works for Unity 2021.3.14f1!

  • @theworldofgamedesign3078

    @theworldofgamedesign3078

    Жыл бұрын

    Glad to hear that!

  • @CESRex21

    @CESRex21

    Жыл бұрын

    Having issues where its ot baking any ideas?

  • @TekEndBen7
    @TekEndBen7 Жыл бұрын

    navmeshagent is not showing can you help me

  • @theworldofgamedesign3078

    @theworldofgamedesign3078

    Жыл бұрын

    Could be the Unity version

  • @intingido9751
    @intingido97519 ай бұрын

    thank you

  • @theworldofgamedesign3078

    @theworldofgamedesign3078

    8 ай бұрын

    You’re welcome

  • @t90gamemakervietnam8
    @t90gamemakervietnam8 Жыл бұрын

    i used Unity2022.2.10f1 when i click Bake nothing happend T.T

  • @theworldofgamedesign3078

    @theworldofgamedesign3078

    Жыл бұрын

    Check the comments if you may, I believe this problem has been solved.

  • @ItsKevin183
    @ItsKevin183 Жыл бұрын

    When I click on "bake", nothing happens. Do you know why?

  • @theworldofgamedesign3078

    @theworldofgamedesign3078

    Жыл бұрын

    Are you using grid for the ground?

  • @ItsKevin183

    @ItsKevin183

    Жыл бұрын

    @@theworldofgamedesign3078 Got it to work, thanks!

  • @DapperNurd

    @DapperNurd

    4 күн бұрын

    @@ItsKevin183 What did you do to fix?

  • @redriver9298
    @redriver929811 ай бұрын

    when the y axis is used it gets stuck

  • @theworldofgamedesign3078

    @theworldofgamedesign3078

    10 ай бұрын

    Please share the code, and you might need to recheck your movement code.

  • @redriver9298

    @redriver9298

    10 ай бұрын

    @@theworldofgamedesign3078 Sorry, I rewrote that code, but when I decided to use this system again, I realized that the problem most likely lies in the scene. The system is working very well now

  • @cyberdrunkdev5256
    @cyberdrunkdev5256 Жыл бұрын

    "Shownavigation is no longer supported and will be removed"

  • @shark1203-
    @shark1203- Жыл бұрын

    Does not work, dislike

  • @theworldofgamedesign3078

    @theworldofgamedesign3078

    Жыл бұрын

    You might have missed something, many have tried and worked for them

  • @nachohotdawg5634

    @nachohotdawg5634

    Жыл бұрын

    Could be a different Unity version