2D Navmesh using Unity & C# / Playmaker / Bolt

Поділитися
Вставка
  • Опубліковано 9 лют 2025

КОМЕНТАРІ • 149

  • @RomiFauzi
    @RomiFauzi  4 роки тому +3

    Shout out to @TheZBillDyl (ua-cam.com/video/W-NIYi1t16Q/v-deo.html), I've found out about this awesome plugin from his video! Check his channel out!

    • @blackdolphin4362
      @blackdolphin4362 3 роки тому

      hello, can we make games with this plugin and earn commercial income?

  • @grublord6215
    @grublord6215 4 роки тому +16

    Wow, I was worrying about creating an AI pathing from scratch and you gave me an answer that requires near no effort, thank you

    • @RomiFauzi
      @RomiFauzi  4 роки тому +1

      You're very welcome! happy to know that!

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

    Thanks

  • @ahamedinhaam906
    @ahamedinhaam906 3 роки тому

    One of the best tutorials ive ever watched, Thx so much

    • @RomiFauzi
      @RomiFauzi  3 роки тому +1

      You're most welcome, happy to hear that!

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

    It works! Thanks for explaining how to adapt NavMesh to 2D.

  • @julienf04
    @julienf04 4 роки тому +2

    thanks for this greatest tutorial, i couldnt find a tutorial like this, you helped me a lot to create my indie game, you already have one more sub

    • @RomiFauzi
      @RomiFauzi  4 роки тому

      You're welcome! Glad to hear that!

  • @gamescreator5040
    @gamescreator5040 4 роки тому

    Thanks a lot man. Finally I found an appropriate solution for 2D pathfinding.

    • @RomiFauzi
      @RomiFauzi  4 роки тому

      You're welcome, happy to help!

  • @Furukkan5
    @Furukkan5 4 роки тому +2

    I've just seen Navmesh yesterday in a project like Hotline Miami and tried to adopt it in my 2D project but as I've seen Navmesh is not that common in 2D projects. You should make an enemy AI like in Hotline, your tuts are great! ^^

  • @umbraonovich941
    @umbraonovich941 3 роки тому +1

    I'm making a shooting game with an up down perspective. The enemies needs to keep the direction of the sprite in line with the direction of movement while they are moving. What should I do?

    • @RomiFauzi
      @RomiFauzi  3 роки тому

      Hi, you can set the rotation manually to follow the direction, perhaps convert the direction of the velocity into and angle using Mathf.Atan function.

  • @gbeebe
    @gbeebe 3 роки тому +1

    Thank you very much, sir.

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

    Can we have links to other tilemaps? I want to have multifloors connected by links

  • @SwampySongs
    @SwampySongs 4 роки тому +1

    After importing my spritesheet from the provided link, my full tile map does not appear the same. If I try and drag and drop a floor from tiles>floor>floor_1, then change it to tiled I get:
    Sprite Tiling might not appear correclty because the Sprite used is not generated with Full Rect or Sprite Mode is set to Polygon mode. To fix this, change the mesh type in the Sprite's import setting to Full Rect and Sprite Mode is either Single or Multiple.

    • @RomiFauzi
      @RomiFauzi  4 роки тому

      You can ignore that message, or you can change it in the Sprite importer settings when selecting the PNG files from the project panel.

  • @12jn00gb
    @12jn00gb 3 роки тому +1

    Can I somehow change NavMeshSurface2D shape manually? It isn't generating well.

    • @RomiFauzi
      @RomiFauzi  3 роки тому

      To be honest, I'm not sure about this, you might need to check the code inside, and see if its possible or not.

  • @손수현-t2b
    @손수현-t2b 2 роки тому

    Wow this is really helpful! Thank you so much!! 😊 🙏

  • @justinlindenthaler2491
    @justinlindenthaler2491 4 роки тому +3

    Thanks for the tutorial! I'm having an issue where my enemy sprite disappears in the Game view once I add the NavMeshAgent component onto its game object. The sprite will still display in the Scene view, it only disappears when swapping to Game view. Not sure if you've seen this before, but any insight would be greatly appreciated. Thanks!

    • @RomiFauzi
      @RomiFauzi  4 роки тому

      You're welcome! Regarding the issue, can you try increasing the sprite sort order on the enemy, so it has greater order than the background sprite order (this is accessible under the SpriteRenderer component)

    • @portaxx8283
      @portaxx8283 3 роки тому

      I'm getting the same problem. It seems to have a problem with my collider?

    • @abdelrhmanyehia8323
      @abdelrhmanyehia8323 3 роки тому

      i have the same problem but it seems that the agent not disappearing but it got rotated -90 in the x axis

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

      I have the same problem, because I forgot to add this line into my enemy's script: "agent.updateUpAxis = false;". Hope this help!

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

      @@abdelrhmanyehia8323 same question here! even I added "agent.updateUpAxis = false;" it still doesn't work. Looks like fall down in Z axis

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

    Terima kasih pak romi, ilmunya sangat membantu...

  • @능글이-m3j
    @능글이-m3j 3 роки тому

    Hello thank you so much!
    I have another question, do you know how to
    bake NavMesh Surface 2D at runtime?

    • @RomiFauzi
      @RomiFauzi  3 роки тому

      You're welcome! I haven't tried this, but I think it should be the same as we do it in navmesh 3d, since it is using the same component as it is, you might want to check this link: learn.unity.com/tutorial/runtime-navmesh-generation

  • @thanh-annguyen3724
    @thanh-annguyen3724 3 роки тому

    Really nice tuto !! Where did you find the NavMeshSurface2d component? it not in my unity.. :/

    • @RomiFauzi
      @RomiFauzi  3 роки тому +1

      Thank you so much, for the component you need to download it first, link is in the description.

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

    I just get a constant error that says "missing target object for unity transform.position
    Edit: I switched the variable to an object variable with the value of my actual player and now it works fine

  • @HY-oz2cb
    @HY-oz2cb 3 роки тому

    Great video. After adding a 2D collider to the floor, do you Remove the 2D collider after baking?

    • @RomiFauzi
      @RomiFauzi  3 роки тому

      Thanks mate! Yes, you can remove it or disable it should also works.

    • @HY-oz2cb
      @HY-oz2cb 3 роки тому

      @@RomiFauzi My enemy and target have 2D collider components and also 2D Rigidbody (set to Dynamic body type). After baking, and running the game, the enemy and target are "pushed" to the sides of the scene. I suspect it is the collider but I cannot remove the colliders from the enemy and target because colliders are needed to detect some other actions in the game play. Do know what I can do to fix this? Thanks in advance

    • @RomiFauzi
      @RomiFauzi  3 роки тому

      @@HY-oz2cb you need to disable or remove the collider used for baking, the collider you have added to the scene for baking.

    • @HY-oz2cb
      @HY-oz2cb 3 роки тому

      @@RomiFauzi Thanks that worked. but i thought we need the colliders so that NavMesh will work?

    • @RomiFauzi
      @RomiFauzi  3 роки тому

      @@HY-oz2cb no you don't need, we only need during baking to define the area that are walkable and not walkable, after baking you can delete or disable as per my first reply 😉

  • @rohandas3718
    @rohandas3718 3 роки тому

    Ur tutorial is grt i have one query
    Like i want to click on the world space and want my object to move there avoiding the obstacles how do i do it?

    • @RomiFauzi
      @RomiFauzi  3 роки тому +1

      Thank you, you can check this if you are using playmaker, even though the video is for 3d scene, but it should work the same with 2d scene.

    • @rohandas3718
      @rohandas3718 3 роки тому

      Basically there is some collider like obstacles i want my object to go where i touch even my player will avoid the obstacles and move where i wl touch i have already done with the navigation part like baking complete but if i just use ray cast for moving object its not workiy

    • @rohandas3718
      @rohandas3718 3 роки тому

      @@RomiFauzi help sir

  • @AlfurV2
    @AlfurV2 3 роки тому +1

    how to rotate to move direction?
    sorry for my bad english.

    • @RomiFauzi
      @RomiFauzi  3 роки тому +1

      You can check the velocity of the agent, and flip the scale value between -1 and 1 depending on the x velocity value.

    • @AlfurV2
      @AlfurV2 3 роки тому

      @@RomiFauzi Im make 2d top down shooter game(hotline miami).Im not making platform game.
      Sorry for my bad english :(

    • @umbraonovich941
      @umbraonovich941 3 роки тому

      @@AlfurV2 I have the same problem as you. Curious if you solved it?

    • @AlfurV2
      @AlfurV2 3 роки тому

      ​@@umbraonovich941 transform.right=agent.velocity;?

  • @kini1350
    @kini1350 3 роки тому

    Thank you so much. Helped a lot :DDD

  • @johnportela9533
    @johnportela9533 3 роки тому

    When I follow the "Navmesh using Tilemap" section the baking works fine if the rooms are connected via one tilemap grid. However I am trying to use this with a random dungeon generator, and upon baking after the dungeon is generating, the walkable surface only covers a single room. The rest of the rooms do not have any NavMeshData for the agents to walk on. It seems like the bake is being cut off or blocked, however there is nothing blocking the connecting paths?

    • @RomiFauzi
      @RomiFauzi  3 роки тому

      To be honest, I don't have any idea what might be the cause of this, are the generated dungeon spawned as the child of the Navmesh generator component (the component that generates the navmesh), cause I remember the walkable area needs to be the child of this object.

  • @Multullar
    @Multullar 4 роки тому

    When i go into the script i can cache the component for NavMeshAgent, but updateRotation and updateUpAxis and all other methods do not show up. Do you know why?

    • @RomiFauzi
      @RomiFauzi  4 роки тому

      What name did you gave to the script?

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

    Thank you for your tutorial, but when the ground of my tilemap is irregular, navmesh will still create a blue ground including all squares. Even the squares that are not painted will display blue. How can I correct it?

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

      For areas that are not painted, you will have to create a dummy collider that fits the no painted areas, and add that collider when generating the mesh.

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

      @@RomiFauzi It means using collader to replace the wall function of navmesh?

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

      @@mengdd6888 yeah basically just to tell the mesh baker, to not bake mesh in that area, after the navmesh is baked, you can disabled this collider.

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

      @@RomiFauzi thank you!!!!My game is roguelike, so rooms are randomly generated, but baking is only for tilemap under one room. What should I do.

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

      @@mengdd6888 if the room is randomly generated, then for area without tiles, you will need to spawn transparent tile that has a collider, to be calculated as obstacle when baking.

  • @SwampySongs
    @SwampySongs 4 роки тому

    When making this, should I only use a rigidbody or a collider? I find that having both causes the agent to just bug out. If I change the collider to a trigger it works, but I figured I would want to give the agent a physical area

    • @RomiFauzi
      @RomiFauzi  4 роки тому

      you need to add a rigidbody, but make it kinematic, so the agent will handle the movement, and if you need to change the collider to trigger, there might be a collider covering the whole environment, check that, and disable it if there any.

    • @SwampySongs
      @SwampySongs 4 роки тому

      @@RomiFauzi if only the agent handles the movement, then how do I have physics interactions? How would I have something like a spring push it away?

    • @RomiFauzi
      @RomiFauzi  4 роки тому

      you need to calculate this force manually, or disable the agent, and set the rigidbody to dynamic the moment the physics interactions starts, and switch it back again after...

    • @SwampySongs
      @SwampySongs 4 роки тому

      @@RomiFauzi Gotcha. Is there a way to use the navmesh to calculate what direction to push the rigidbody in? Then maybe I can stop from setting the navmesh destination and only use the dynamic rigidbody.

    • @RomiFauzi
      @RomiFauzi  4 роки тому

      yes you can use the agent.desiredVelocity, more about it can be read here: answers.unity.com/questions/252292/is-there-a-way-to-check-agent-velocity-for-navmesh.html

  • @gustavosalmeron2013
    @gustavosalmeron2013 3 роки тому

    Can the enemies avoid going through each other? I'm making a game with multiple npcs with a collider2D each.

    • @RomiFauzi
      @RomiFauzi  3 роки тому +1

      with agent component, each enemies should avoid each other by default.

  • @MichelangeloBedetti
    @MichelangeloBedetti 3 роки тому

    Yes, but what if you need to animate the enemy sprite?

    • @RomiFauzi
      @RomiFauzi  3 роки тому

      You can sync the navmesh agent velocity with the animator parameter that drives the idle to walk animation....

  • @lofiroom_stories
    @lofiroom_stories 4 роки тому

    Is this plugin a safe choice for those looking for creating professional games? Like. I wonder if it causes bugs on builds and stuff.

    • @RomiFauzi
      @RomiFauzi  4 роки тому +1

      So far from my testing it seems to work just fine, but you'll need to do more testing on your end probably.

    • @lofiroom_stories
      @lofiroom_stories 4 роки тому

      @@RomiFauzi Thanks. I'll will. :)
      Great tutorial. Btw.

  • @Tim_Photo
    @Tim_Photo 4 роки тому

    Thanks for this tutorial! The only problem I'm having is when I drag the tiles in they are absolutely tiny compared to the scene, but if I shrink the camera to keep the scale of the tiles the camera icon takes up the entire frame. Do you have any ideas where I'm going wrong?

    • @RomiFauzi
      @RomiFauzi  4 роки тому

      You're most welcome. For that issue, you can change the pixel per unit settings in the Sprite Importer settings by selecting the PNG (image) asset in the project panel, try to lower the values to make the sprite bigger in the scene.

  • @zyn3ria714
    @zyn3ria714 3 роки тому

    Hi Romi, can I use this in a URP project or just Unity 2D?

    • @RomiFauzi
      @RomiFauzi  3 роки тому

      Yes you can use it for URP, sprites and tilemap actually work the same regardless the renderer.

  • @santiagojuarez1289
    @santiagojuarez1289 4 роки тому

    really good video, thanks man

  • @PrizrakSHIZA
    @PrizrakSHIZA 3 роки тому

    can i set different costs for different tiles, or only for entire tilemap?

    • @RomiFauzi
      @RomiFauzi  3 роки тому

      For different cost, I think you have to script it manually.

    • @PrizrakSHIZA
      @PrizrakSHIZA 3 роки тому

      @@RomiFauzi yeah. 2d navmesh cant do that. Only if place different tile types on diff tilemap) so i made it via A*

  • @HY-oz2cb
    @HY-oz2cb 3 роки тому

    The strangest thing happened. I managed to get the NavMesh working, i.e. agent follows the target. Then I Clear the mesh and then Bake again, the blue overlay of the "walkable" area does not appear anymore!

    • @RomiFauzi
      @RomiFauzi  3 роки тому

      To bake you need to reenable the collider of the scene you have disabled after previous baking.

    • @HY-oz2cb
      @HY-oz2cb 3 роки тому

      @@RomiFauzi You da man! thanks!

  • @mainchannel8828
    @mainchannel8828 4 роки тому

    When I click bake my scene view stays the same, no lines of any kind are shown idk if this is me not doing anything right but I experienced the same problem using the astar pathfinding project so I think it's some unity setting I might have turned off, anyway really interesting vid

    • @RomiFauzi
      @RomiFauzi  4 роки тому

      You should be able to see the baked mesh if you open the navigation panel, have you try that?

    • @tomschwartz8756
      @tomschwartz8756 3 роки тому

      In the scene window, do you have the Gizmos button on? If so, try clicking the little arrow next to the Gizmos button, and scrolling down to where it says Colliders (or colliders 2D, can't quite remember) - make sure the arrow next to it is also clicked.

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

    Can you use this for free? Like if I were to sell a game on Steam using this?

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

      Yes you can, it is released under MIT license

  • @JongHyunSM
    @JongHyunSM 4 роки тому

    can you make the enemy walk random patrol at first start?

    • @RomiFauzi
      @RomiFauzi  4 роки тому

      I'll see what I can do about it...

  • @ravanin
    @ravanin 4 роки тому

    are either tile rule or sprite shape, supported for this?

    • @RomiFauzi
      @RomiFauzi  4 роки тому

      Yes, both are supported, you can check out the timestamp for both method, I've explained both ways in this video.

    • @ravanin
      @ravanin 4 роки тому

      @@RomiFauzi I think you are confusing sprites with sprite shape and tile map with tile rule. they are different things.

    • @RomiFauzi
      @RomiFauzi  4 роки тому +1

      sprite shape works, as long you've added a collider with the same shape as the sprites, because it relies on the collider shapes to define the navmesh. And tile rule also works, because the generated tile using tile rule it is basically a tile map, as long each layr of tilemap are set to the correct type in the NavMesh Modifier settings, it will define the navmesh correctly.

    • @ravanin
      @ravanin 4 роки тому +1

      @@RomiFauzi Thanks. I'll be definitely using this.

  • @blackdolphin4362
    @blackdolphin4362 3 роки тому

    hello, can we make games with this plugin and earn commercial income?

    • @RomiFauzi
      @RomiFauzi  3 роки тому

      Yes you can since the plugin is under MIT license.

  • @nonoodwhatever4263
    @nonoodwhatever4263 3 роки тому

    not sure what to say, but thanks! I now see the error of why!

  •  4 роки тому

    Very good and detailed explanation. Thanks!

    • @RomiFauzi
      @RomiFauzi  4 роки тому

      You're welcome! Glad it was helpful!

  • @andrekadow
    @andrekadow 4 роки тому

    Great video! Could you make a tutorial for a roguelike game using playmaker? :) I am a designer starting to code...

    • @RomiFauzi
      @RomiFauzi  4 роки тому +1

      Thank you so much, I can't promise it, but I'll see what I can do..

  • @chrischains9947
    @chrischains9947 3 роки тому

    nice stuff :D thank you!

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

    For some reason my enemy doesn't chase me until i walk further away.

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

      Could it be that the stopping distance value is to big, that the player is withing stopping distance range on start?

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

      @@RomiFauzi Actually it doesn't matter if i walk further away or closer. It doesn't chase me until my player has a little bit of movement

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

      @@robbybobbijoe are you using c# or playmaker for the logics?

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

      @@RomiFauzi c# I guess?

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

      @@RomiFauzi Apparantly, when I remove this enemy script it works normallt. I have no idea how it could be interfering so much
      using System;
      using System.Collections;
      using System.Collections.Generic;
      using UnityEngine;
      public class Enemy : MonoBehaviour
      {
      public GameObject effect;
      public static event Action OnEnemyKilled;
      [SerializeField] float health, maxHealth = 3f;
      Rigidbody2D rb;
      private void Awake()
      {
      rb = GetComponent();
      }
      private void Start()
      {
      health = maxHealth;
      }
      public void TakeDamage(float damageAmount)
      {
      health -= damageAmount;
      if (health

  • @png_cozy8594
    @png_cozy8594 3 роки тому +1

    does it work in 3d

    • @RomiFauzi
      @RomiFauzi  3 роки тому

      In 3d, you don't need this script, you can use unity navmesh feature right away, it is intended for 3d.

  • @WalleNilsson
    @WalleNilsson 3 роки тому

    I dont have navigation next to the inspector

    • @RomiFauzi
      @RomiFauzi  3 роки тому

      You can access it via the menu "Window > AI > Navigation"

    • @WalleNilsson
      @WalleNilsson 3 роки тому

      @@RomiFauzi Big thanks

    • @RomiFauzi
      @RomiFauzi  3 роки тому

      You're welcome!

  • @criptas1985
    @criptas1985 4 роки тому

    Hi!! Epic video! Tnx so much! Can i use in my game?

    • @RomiFauzi
      @RomiFauzi  4 роки тому +1

      You're welcome, sure you can use it, I believe the plugins is open source.

  • @esathanatabek9905
    @esathanatabek9905 4 роки тому

    Thank you for the tutorial. Can you show how to make a 2Dtopdown movement system like in this video (in Playmaker). I searched everywhere for it but I can't find a solution. It would be a huge help. Thank you.

    • @RomiFauzi
      @RomiFauzi  4 роки тому +1

      You're welcome, regarding the 2d top down movement, I'll see what I can do about it.

  • @Moon_579_XD
    @Moon_579_XD 4 роки тому +1

    Bro pls describe your cpu specs pls pls pls ?

    • @RomiFauzi
      @RomiFauzi  4 роки тому +1

      I'm using a 3 year old laptop, with i7 6700HQ cpu, 16 GB, and a GTX 950M, also I'd recommed using SSD instead of HDD.

    • @Moon_579_XD
      @Moon_579_XD 4 роки тому

      @@RomiFauzi thanx keep going

  • @F3L0
    @F3L0 3 роки тому

    Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you Thank you

  • @tttrrrrt1229
    @tttrrrrt1229 3 роки тому

    Thank you! :)

  • @AkkuVlogz
    @AkkuVlogz 3 роки тому

    thanks a lot dude

  • @phattrinhtan4562
    @phattrinhtan4562 3 роки тому

    why don't it avoid wall ?

    • @RomiFauzi
      @RomiFauzi  3 роки тому

      Perhaps there is a mistake in your setup?

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

    thx a lot

  • @fisashgames6704
    @fisashgames6704 4 роки тому

    hi, good video. hello from russia! my enemy ignores obstacles(( although the navmesh shows that it is. help plz

    • @RomiFauzi
      @RomiFauzi  4 роки тому

      Is the navmesh baked correctly? see if there is a hole on the navmesh around the obstacles?

  • @boldfrog82
    @boldfrog82 4 роки тому

    Nice

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

    Hi, this works, but why does my agent overlap the non-walkable agents?

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

      TBH I'm not sure, how to repro this?