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
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
Жыл бұрын
Appreciate the help, I’ll pin your comment.
It was the most easy-to-understand explanation of the videos and sites I've seen so far.
For anyone who can't find "NavMesh Surface2d", this is the new way from repo. 1.add navigation surface 2.add navmesh collectSoures2d
@theworldofgamedesign3078
Жыл бұрын
Thank you
@yanbatista2828
Жыл бұрын
thaaaank youu!!!!!!!!!
@Ziplock9000
Жыл бұрын
Even the repo itself in June 2023 still refers to Surface2d. Thanks
@user-eo5kk1sh3e
4 ай бұрын
But it doesn't work
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
Жыл бұрын
My pleasure :)
7 hours of trying to make an AI with pathfinding, meanwhile this video makes it so much quicker ty ty
Thanks! Really helpful. I will add that if your world scale is too small, the nav mesh agent will have some difficulties moving sometimes.
Incredible tutorial, no BS or intro just straight to the point.
@theworldofgamedesign3078
6 ай бұрын
Exactly, because how much I struggled with those entries, I decided that I will never do that in my videos.
Thanks! It is short and useful! You saved my time.
@theworldofgamedesign3078
Жыл бұрын
Glad to hear that!
You have resqued me! Thank You! OMG It's working!
感谢你的视频,也感谢navmeshplus的作者,看完视频两个小时就完成了我的导航系统😘😘
@theworldofgamedesign3078
Жыл бұрын
太棒了,很高兴听到这个消息
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
Жыл бұрын
Thanks for the tip! I pinned your comment.
for anyone not finding the 2D option, they changed some things and its explaned well in the repo. it should still work
@theworldofgamedesign3078
Жыл бұрын
Thanks for the heads up
@Ziplock9000
Жыл бұрын
Actually the repo still refers to the Surface 2D.
Very informative and usefull tutorial. Thanks.
This tutorial is a miracle in my life. Might save my Game Thesis.
@theworldofgamedesign3078
8 ай бұрын
Glad I could help :)
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
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
Ай бұрын
WTF, Thank you!!!!!
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?
Can't make it work on tiled sprites. Did someone made it work with tiled sprites?
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
Жыл бұрын
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.
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?
I dont see a NavMeshSurface2d? Am I doing something worng..
Pressing Bake doesn't seem to do anything for me. The navmesh doesnt show. It takes a second to calculate but nothing changes.
@wendellfranco2259
Жыл бұрын
me too, the mesh do not appears
@nachohotdawg5634
Жыл бұрын
R u using grid for the ground?
this doesnt work in version 2019.4
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
Жыл бұрын
U mean the collider? If so you can make an empty game object with a circle collider then add your object to it
How can i calculate and draw path from object to target with this ? PLEASE ANSWER IM DESPERATE
@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);
I have a question can you onley use tilemaps ? or is there a way so that I could use other gameobjects
@theworldofgamedesign3078
Жыл бұрын
I think for this specific package you would need a tilemap
not working nothing happens when baked
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
Жыл бұрын
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
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
Жыл бұрын
Thank you for clarification
Why does it say "This component will be removed in future releases, use NavMeshExtensions instead."
@SpirityLandia
Жыл бұрын
NavMeshExtensions not exists here :(
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
Жыл бұрын
Glad I could help
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
Жыл бұрын
No not really, I’ve pinned a comment today, check it out.
@kryuza3191
Жыл бұрын
@@theworldofgamedesign3078 I don't see the pinned comment and im having troubles because navmesh surface2d isn't appearing to mine as well
@nachohotdawg5634
Жыл бұрын
It could be due to a different Unity version
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
Жыл бұрын
add this to your agent object > agent.updateRotation = false;
@Ziplock9000
Жыл бұрын
Same issue.
@user-gn6qp9hu2l
Жыл бұрын
Did you manage to fix the issue?
@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
please, can you help me? I'm trying to use Navmesh surface 2D but its missing :c
@theworldofgamedesign3078
Жыл бұрын
Try same version in the video
how do you make this work for 2D Side-Scroller game ?
@theworldofgamedesign3078
Жыл бұрын
Perhaps by constraining Y movement in the rigidbody
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
Жыл бұрын
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
Жыл бұрын
Good to hear!!
@mohammadumarsajid8214
Жыл бұрын
@@andersonkaueplebani5581 after seeing all the comments for my solution, Thank God i didnt skipped your comment, it worked for me
This is use for commercial and non commercial? Anywhere Or more question A* pathfinding better than this ?
@luanmartinssilva1239
Жыл бұрын
Nice vídeo ! In my project, NavMeshAgent and Navigation Windown are missing. Have a solution for this ?
@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?
This is awesome. Thanks! Is there a way to face an agent in the direction of moving?
@theworldofgamedesign3078
Жыл бұрын
Thank you, this could be made from the script, having a function that rotates the agent towards the moving direction.
@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
Жыл бұрын
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);
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
Жыл бұрын
Thanks for the clarification
@mohammadumarsajid8214
Жыл бұрын
still cant see bro
Nothing happen when I click Bake, do you have any Idea what I could have messed up ?
@nachohotdawg5634
Жыл бұрын
Grid used for the ground?
@skave7228
Жыл бұрын
@@nachohotdawg5634 Yup
Thank you, I just had to change a few things because it updated but it works for Unity 2021.3.14f1!
@theworldofgamedesign3078
Жыл бұрын
Glad to hear that!
@CESRex21
Жыл бұрын
Having issues where its ot baking any ideas?
navmeshagent is not showing can you help me
@theworldofgamedesign3078
Жыл бұрын
Could be the Unity version
thank you
@theworldofgamedesign3078
8 ай бұрын
You’re welcome
i used Unity2022.2.10f1 when i click Bake nothing happend T.T
@theworldofgamedesign3078
Жыл бұрын
Check the comments if you may, I believe this problem has been solved.
When I click on "bake", nothing happens. Do you know why?
@theworldofgamedesign3078
Жыл бұрын
Are you using grid for the ground?
@ItsKevin183
Жыл бұрын
@@theworldofgamedesign3078 Got it to work, thanks!
@DapperNurd
4 күн бұрын
@@ItsKevin183 What did you do to fix?
when the y axis is used it gets stuck
@theworldofgamedesign3078
10 ай бұрын
Please share the code, and you might need to recheck your movement code.
@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
"Shownavigation is no longer supported and will be removed"
Does not work, dislike
@theworldofgamedesign3078
Жыл бұрын
You might have missed something, many have tried and worked for them
@nachohotdawg5634
Жыл бұрын
Could be a different Unity version