How to Use the New Navigation System in Godot: Enemy Pathfinding

Поділитися
Вставка
  • Опубліковано 15 вер 2022
  • Learn to Code from Zero, With Godot: www.gdquest.com/
    Godot Node Essentials - Godot 4 edition: school.gdquest.com/products/g...
    ---
    📚 THE LINKS
    Godot 3.5 open-source demos: github.com/gdquest-demos/godo...
    ---
    👥 CREDITS
    Video edited by Nesi: / nesiawesomeness
    ---
    💌 JOIN US
    Come chat on Discord: / discord
    Follow us on Twitter: / nathangdquest
    ---
    📝 CC-BY LICENSE
    This video is licensed under the CC-By 4.0 license: creativecommons.org/licenses/...
    You can attribute it to "CC-By 4.0 - GDQuest and contributors - www.gdquest.com/"

КОМЕНТАРІ • 63

  • @FirebelleyGames
    @FirebelleyGames Рік тому +44

    Great content! Question though - isn't the Navigation2D node irrelevant now? If I understand correctly, you can do everything you show in the video without it since the NavigationServer handles everything.

    • @Gdquest
      @Gdquest  Рік тому +22

      It's true that the node is deprecated and you don't need to have it. I'm using the node to change the connection margin between navigation polygons primarily. As mentioned in another comment, there's also a bug that requires the node right now for avoidance (for which I use the same setup).Thanks for pointing this out! I've pinned your comment for others to see.

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

      @@Gdquest looks like it has been removed from the Godot 4 Beta1 just released.

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

      @@nathanwaterman4380do you know how to use it? I cant find a video.

  • @timothy8428
    @timothy8428 Рік тому +20

    This gives me a great idea for a game. You control a little yellow circle that munches dots in a maze, while some ghosts chase you around.
    I'm going to call it... MacPan, yeah.

  • @camcam983
    @camcam983 Рік тому +10

    This channel should be having more than 1 million subscribers

    • @lukeh5325
      @lukeh5325 Рік тому +5

      I feel like GDQuest is the Brackeys of Godot, but not enough people use Godot

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

      @@lukeh5325 🤝 Agreed, l think Godot will grow overtime

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

    Thank you so much for all your videos, really valuable information every time! :)

  • @asciiboi5400
    @asciiboi5400 Рік тому +2

    Thanks for all the great content. You helped me get started a lot.

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

    Nice video keep up the good work GDQuest

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

    Thanks for this tutorial 🙂 It worked for me

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

    This is great! I was hoping there'd be a tutorial/guide available soon! Question: would frequently recalculating the path to the player have a significant effect on performance?

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

    Thanks for this guide, you the only one who tell about this pathfind system. I think you should have more likes and subscribers!

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

    Thank you! 😁

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

    Lifesaver. Thanks to you I can now win at my unis game jam

  • @alexanderstreng4265
    @alexanderstreng4265 Рік тому +13

    Navigation 2D and Navigation node are deprecated in Godor 3.5 . you don't need for navigation to work. However, there seems to be a bug in navigation obstacle that still needs the deprecated node, though it has been fixed in 3.5-rc1.

    • @alexanderstreng4265
      @alexanderstreng4265 Рік тому +5

      3.5.1-rc1

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

      @@alexanderstreng4265 ahhhh this might explain a thing or two... I'll have to update

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

      Has it been? I'm trying to setup navigation in 3.5.1 and still it requires to be a child of Navigation2D it seems.

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

    Great video! Is there an example for a platformer/sidescroller game?

  • @MrBrigadierArchived
    @MrBrigadierArchived 11 місяців тому

    Thanks for the video, and I have some different newbie question now: is there real profit for declaration variables with simple " = " or with " := "?

  • @dukemagus
    @dukemagus Рік тому +2

    @GDQuest, can you consider a more thorough course on the gdquest site to use the new navigation system to make grid based movement (for roguelikes or turn based strategy games)? The new navigation server seems more powerful and faster to implement than manually implementing A* or Dijkstra's algorithm to calculate routes. It can also take 3d into account, and which on A* would need to add costs values to every square/hex on the map. It seems like the perfect system to power a turn based tactics framework, and if it can multi thread as described, it would allow route calculation for many characters without causing a stutter when it has to calculate routes at each interval

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

      But the A* is already implemented in the engine

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

      On a grid AStar is the way to go, this calculates the fastest geometric path to a point on a polygon - it doesn't support grids.

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

    Thanks for the tutorial! I want to know how stop the kinematic body if it is being stopped by other kinematic bodies that also want to reach the target position.

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

    Question, how would the new navigation system work when it comes to creating a patrol state for an enemy?

  • @rudy_kolibri
    @rudy_kolibri Рік тому +2

    could you make a video how to make it work nicely with tilemap

  • @Jose.Eduardo.C
    @Jose.Eduardo.C 5 місяців тому

    When I ctrl+click and drag to create an onready variable, the new variable doesn't come typed like with the :timer that appears on the video... Is there a toggleable option to make this the default behavior?

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

    Will you guys cover the navigation system in 3d?

  • @DA-cl4ww
    @DA-cl4ww Рік тому +2

    How is performance using this, updating the agents who also avoid eachother's target positions every 5th of a second or so? My own steer logic atm let's me use about 1000 rigidbody "agents" in groups atm before slowdows. Was gonna make it into a gdextension but if the inbuilt is more performant...

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

      If you use the pathfinding on every agent individually, it may be expensive, but if you group them, it should probably be as fast. I'm not sure if your use case is well supported out of the box because I haven't tested it. The built-in steering is integrated into the navigation system, so I'm not sure that you can make groups of agents with a single leader running the expensive pathfinding algorithm and others following with steering using the navigation system's steering.I think you'd have to code all the other agents in the group yourself as something like boids.

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

    Is there a way to make this work with a tilemap?

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

    hi a quistion how do i get player from a other scene with this ?

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

    Is there a 3d tutorial for godot 3.5? I can't get my kinematic body NPC to move along a set path between way points.

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

    Where can you set Edge Connection Margin in Godot 4 now that Navigation2D node is gone?

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

    How to write a code when I have an enemy who spawning in a room, when I can't just use NodePath and point it on player??

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

    Is there a method with low performance cost to check the distance between player and target on runtime?

    • @mokafi7
      @mokafi7 Рік тому +2

      global_position.distance_to() works fine no?

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

    Will a similar method work in 3d?

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

    How would one work with the navigation agent if you wanna follow a path?
    let's say the npc can choose between multiple states like Patrol and FollowTarget.
    In an open level i want the npc to walk its PatrolPaths until a new valid Target enters its Area/RayCast or occludes its Light2D FoV.
    Would you still use NavigationAgent2D like that?
    I suppose you just set the next baked point for the Path2D and call set_target_location(patrol_point)...
    And how would one extend the NavigationArea?
    Let's say the npc is patrolling on its Path and a player comes along.
    The npc will chase the player until the end of the NavigationArea2D and then it will just sit there.
    I could add a new NavigationArea2D but at the same time this would mean i am fumbling with the navigation of every other NPC that uses the same navigationlayer...
    So baking the polygons beforehand is a must?

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

      If you want to go from a predefined patrol to moving to a target, you can set the target location in such a way the AI patrols until the player or an enemy comes in range. When this happens, you change the target location to the enemy.
      You may also use a state machine to control when the AI is in the patrol state (and plays, for example, a walking animation) and when it's in a pursuit state.
      The reason you may want to patrol with the navigation system is that your AI will be able to avoid moving obstacles (such as other AI agents) or navigate the level automatically without you having to draw patrol paths by hand. But you will need to check if the path it takes is good enough.

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

      @@Gdquest thx.
      I got a patroling paths and following the player working.
      How would you expand the NavigationArea2D if needed? If the current runs out of bounds and the pursuit needs to go on?

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

    When I try to instance another enemy I get an error that reads "invalid get index 'global_position' (on base: 'null instance').

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

      New question. How do I assign the path to player automatically when instancing a new enemy?

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

    How can i learn godot efficient ply?

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

    Ctrl click drag into auto typed var ? :O

  • @beckkyakintunde1714
    @beckkyakintunde1714 9 місяців тому

    How do i use pathfinding for a 2d platformer

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

    How would u get this to work in Godot 4 beta 7

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

    your video’s are amazing- can you help with a few tNice tutorialngs

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

    _please _talk _about _how _to _do _neural _networks =D

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

    That's not working, thanks

  • @g-funny2171
    @g-funny2171 Рік тому

    sa

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

    last

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

    so basically if you have two enemies with different sizes, you have to bake another navigation layer and so on. useless.
    ok im off to write my own navigation, enough with this.

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

      I think you misunderstood. I don´t see where you could see that in this video as we only cover one agent. But you could duplicate the enemy ship and all ships would follow the player with no code changes.

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

      @@Gdquest I said with different sizes. how would it work?

  • @teo2805
    @teo2805 Рік тому +3

    I'd like to see a video on Astar + grid movement 🥲

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

      I think they quietly added an AStarGrid2D class to Godot 4. Documentation on it is still a bit sparse, but it seems promising for pathfinding in grid based games.

    • @Gdquest
      @Gdquest  Рік тому +2

      We cover Astar for grid based movement in this free tut series: www.gdquest.com/tutorial/godot/2d/tactical-rpg-movement/lessons/04.pathfinding-and-path-drawing/

  • @CrownedZombie-
    @CrownedZombie- 4 місяці тому

    after a little tries this is te best i got from the code
    extends KinematicBody2D
    var velocity := Vector2.ZERO
    export var enemy_speed = 200
    onready var player = $"../Player"
    onready var agent :NavigationAgent2D= $NavigationAgent2D
    onready var timer = $Timer
    func _ready():
    agent.set_target_location(player.global_position)
    timer.connect("timeout",self,"update_player_position")
    func _physics_process(delta):
    if agent.is_navigation_finished():
    return
    var direction = global_position.direction_to(agent.get_next_location())
    var desired_velocity = direction * enemy_speed
    var steering = (desired_velocity - velocity) *delta * 4.0
    velocity += steering
    velocity = move_and_slide(velocity)
    func update_player_position():
    agent.set_target_location(player.global_position)