Godot 4 3D - AI Pathfinding/Navigation

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

КОМЕНТАРІ • 170

  • @drobison100
    @drobison100 Рік тому +298

    Godot 4.1 release made some changes to NavAgent methods, the docs will be your friend but simply:
    nav_agent.set_target_location(target_loc) is now nav_agent.target_position = target_loc
    nav_agent.get_next_location() is now nav_agent.get_next_path_position()
    Thank you for the content, please release more as often as possible, I eat it all up

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

      Thanks drobison100

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

      Thanks drobison100

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

      Thanks drobison100

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

      Thanks drobinson100

    • @Kman100003
      @Kman100003 10 місяців тому +2

      This might explain my Getting a non_existent_function for 'get_next_location() function call

  • @AyoGodot
    @AyoGodot Рік тому +108

    For anyone having errors with the nav agent functions, it has been changed to another method, e.g, set_target_location() is now set_target_position()

    • @iBurntMyCerealAgain
      @iBurntMyCerealAgain Рік тому +21

      Yes,
      "var next_loctation = nav_agent.get_next_location()" ---> "var next_loctation = nav_agent.get_next_path_position()"
      "nav_agent.set_target_location(target_location)" ---> "nav_agent.set_target_position(target_location)"

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

      @@iBurntMyCerealAgain omg, u a my hero

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

      @@iBurntMyCerealAgain Thank you so much.

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

      Thank you

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

      @@iBurntMyCerealAgain
      Line 17: Cannot call non-static function "get_next_path_position()" on the class "NavigationAgent3D" directly. Make an instance instead.
      Line 24: Cannot call non-static function "set_target_position()" on the class "NavigationAgent3D" directly. Make an instance instead.
      What should I do?

  • @animejoe4041
    @animejoe4041 2 роки тому +39

    You are my new favorite person of the month! ;)
    I've been banging my head trying to figure out how to do this in Godot 4 and you came to the rescue! I could get my enemies to move from one point to the next point and that's it. They'd stop once they reached my starting location. I couldn't figure out how to get them to keep chasing me.

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

      Happy you were able to find it useful! Thanks for watching. :)

    • @wowanimallia
      @wowanimallia 24 дні тому

      same problem i'm facing now

  • @GaryParkin
    @GaryParkin Рік тому +34

    Thank you. this works perfectly.
    In Godot 4.0.2 Stable,
    3:15 nav_agent.set_target_location(target_location) change to nav_agent.target_position = target_location
    4:06 var next_location = nav_agent.get_next_location() change to var next_location = nav_agent.get_next_path_position()
    It should work find from there. Looks like the dev's changed from setters to properties.
    Also I needed to set my Agent Height Offset to .45 to make him stick to the ground.

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

      it's giving me the following issue:
      cannot call non-static function "get_next_path_position()" on the class "Navigationagent3d"
      what do i do about this..? am a total rookie I admit

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

      Thank you! This also works in version: Godot_v4.2.1-stable

    • @Weebletmon
      @Weebletmon 2 місяці тому

      You're the best, thanks. 👍

    • @quackncheese
      @quackncheese 2 місяці тому

      @@m3gasn1p3r You're calling the function on the class itself (Navigationagent3d), not the instance (the nav_agent variable). Simply do nav_agent.get_next_path_position()

  • @Realgooodmusic
    @Realgooodmusic 11 місяців тому +5

    Does anyone know what the environment is? I can't find in Godot 4

  • @GreySectoid
    @GreySectoid 2 роки тому +21

    Nice example. Switching from Unity to Godot so these tidbits really help.

    • @DevLogLogan
      @DevLogLogan  2 роки тому +5

      Thanks! Let me know if there’s any tutorials/examples in particular you could use. Looking for more ideas on what to make.

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

      @@DevLogLogan Not sure if there's something comparable in Godot but here's some ideas: animation (state machines), collision detection (terrain vs objects), particle effects (and emitters), game state serializing (save/load functionality).

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

      @@DevLogLogan Advanced Ai is onenof those ideas.

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

    Wouldn't it be great if we could draw or manually edit our navmeshes?

  • @WeirdFix
    @WeirdFix 3 місяці тому +2

    so my enemy just moves to the centre of the map, instead of following the player?

  • @alextheguy4469
    @alextheguy4469 Рік тому +6

    In Godot 4.0.3 stable, I was getting a nonexistent function error for the "update_Target_Location" function. It's not nav_agent.set_target_location" in 4.0.3. Instead, use "nav_agent.set_target_position" and it should work. Like others have said, similar thing with the _physics_process function. it's "var next_location = nav_agent.get_next_path_position" instead of "get_next_location"

  • @bodamat
    @bodamat 2 роки тому +15

    Wow how simple it in Godot 4. But it wouldn’t so good if you don’t explain so clearly. Thanks you so much 🙂

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

      Slava Ukraini!

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

      @@DamnMascus Героям слава!

  • @plutoniumgamestudio
    @plutoniumgamestudio Рік тому +7

    For anyone wondering, this is working in godot 4.0 stable, 1 thing you need to change is in the:
    func update_target_location(target_location) function, you need to change it to: func update_target_location(target_location) -> void:

  • @MoogieSRO
    @MoogieSRO Місяць тому +1

    Soooo, nobody else in the world is getting "Navigation map synchronization error. Attempted to update a navigation region with a navigation mesh that uses a cell_size of 0.00999888 (bunch of numbers) while assigned to a navigation map set to a cell_size of 0.25"? Just me? Alrighty then. Also had to defer the enemy's _physics_process for 1 frame because it was trying to use the navmap before it was initialized, nobody got that one, either? Cool, cool.

  • @Sean-gx1sf
    @Sean-gx1sf Рік тому +6

    Interesting, what happens if there is no path to the destination? For example, the character is on an isolated platform that cannot be reached, what happens?

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

      The agent walks towards the target and stops when he can't go any further.
      "is_target_reachable()" to check if the destination is reachable

  • @UltimatePerfection
    @UltimatePerfection 4 місяці тому +1

    Does the navigation region check the children recursively to build the navmesh? E.g. if I have level object thing that has its own children, will it bake for the children too?

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

    Hey, great tutorial! Helped me a lot setting up an enemy, thanks!
    I have one additional question, though:
    How do I make the node rotate to where it's going? I tried look_at() but it rotates suddenly, without any kind of smoothing. Tried using angle_to() and then a lerp_angle(), but the rotation is not right either.
    Cheers.

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

      var rotation_speed = 20
      $MeshInstance3D.rotation.y = lerp_angle($MeshInstance3D.rotation.y, atan2(-velocity.x, -velocity.z), delta * rotation_speed )
      Works good :)

    • @vas-poenitentiae-08
      @vas-poenitentiae-08 Рік тому

      I’m just using a sprite3d with billboard mode activated.

  • @shinetra7507
    @shinetra7507 16 днів тому +1

    does anybody know how to add a code that make the enemy look at the player within this code?

  • @maxismakingstuff
    @maxismakingstuff 10 місяців тому +4

    Great tutorial and to the point. Little examples of "gotchas" too. I was able to set this up in an evening due to how little time it took to implement this solution. Thanks man.

    • @memze1148
      @memze1148 2 місяці тому

      HOW?, IT TAKES ME LIKE TWO DAYS TO IMPLEMENT A FEAUTRE LIKE THIS

  • @synthnostate
    @synthnostate Рік тому +6

    Thanks! That was easier than expected. Momentum was a nice touch too.

  • @vas-poenitentiae-08
    @vas-poenitentiae-08 Рік тому +7

    How did you get the enviroment node? Has it been renamed?

  • @Elrinth
    @Elrinth Рік тому +4

    amazing tutorial, thanx for sharing! the enemies still move in like a triangle formation. looks hilarious :D

  • @NewFunnyAnimations
    @NewFunnyAnimations 3 місяці тому +1

    thanks for the help! Helped a lot

  • @Robin_H.I
    @Robin_H.I Рік тому +2

    I tried the code and typed it in two times even changed location to position as the comments said but still nothing works. So if anyone sees this comment and knows how to help i would greatly appriceate it.

  • @analbinodragon
    @analbinodragon 3 місяці тому +1

    I can't get the npc to move at all, I've followed the other comments with the updated code but nothing works T_T

    • @thedarkknightplayz686
      @thedarkknightplayz686 2 місяці тому

      I had the same problem, I fixed clicking "Bake NavigationMesh" button in "NavigationRegion3D" view, I forgot bake the nav region. I hope this fixes your problem as my :)

  • @TheMakuzao
    @TheMakuzao 2 роки тому +6

    This is actually just perfect, thank you very much

  • @estusf1ask
    @estusf1ask 3 місяці тому +1

    This was a perfect tutorial, no notes! Using this i cut out like 100+ lines of code that was basically doing this the hard way XD

  • @thecringeslayer4897
    @thecringeslayer4897 3 місяці тому +1

    0:00 What node is the "environment?"

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

    thank you! nice job

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

    thanks you. can you make more of these videos sir?

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

    my enemies just go to the origin spawn of the player, they dont follow me:( i just printed what the "player.global_transform.origin" was showing, and it just print the spawn coordinates....when i move it doesnt change...that must be the error, but i can solve it. need help please.

    • @basscrowdead
      @basscrowdead 7 місяців тому +1

      Exact same problem. Make sure that the CharacterBody3D is not a Child Of any other nodes. Fixed it for me.

    • @gurkenpoo
      @gurkenpoo 7 місяців тому +1

      @@basscrowdead I had fixed it, and thats the way i did it. thank you very much for the help!

  • @Creeg81
    @Creeg81 6 місяців тому +1

    i followed this tutorial exactly and the character is navigating towards the enemy. idk how to fix this so if someone could help me out that would be great

    • @user-xsn5ozskwg
      @user-xsn5ozskwg 6 місяців тому

      It sounds like you might have used the wrong scripts for the wrong scenes or possibly assigned things wrong in the world script if you're using similar code for the player and enemies.

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

      @@user-xsn5ozskwg OK thank you

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

    can you use navmesh in games or is used only for demos like gmesh? cause I've never seen anyone use navmesh with actual 3d terrain meshes... just squares and cubes.

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

    I have no idea what I'm doing wrong but my screen just goes black or grey when I test with the added enemy.

  • @Chris-jp6ll
    @Chris-jp6ll Рік тому +2

    Nice Tutorial! Any idea/tip how to handle if this 3 enemies just should walk to a specific location and stop there?
    I'm experimenting with this setup (but in 2D) and my agents push each other around (understandably) when they have reached the destination as only one of them can stand on the exact location. Just can't figure out a (for me proper) way how to handle this kind of "group to target movement".
    Yes, there's the "Target Desired Distance" Option of the NavigationAgent but that gets hardly a solution, the more Units are walking around.

  • @thesomeone2nd
    @thesomeone2nd 16 днів тому

    Really cool and helpful tutorial thanks a lot. Everything works fine i just have a red error whenever i run the project saying "NavigationServer navigation map query failed because it was made before first map synchronization". Anyone who knows how to fix that?

  • @nabir14
    @nabir14 3 місяці тому +1

    This helped a lot thanks

  • @DavidCordero-v3g
    @DavidCordero-v3g 11 днів тому

    invaid call nonexistent function 'set_target_location' inbasec'navigationagent3d

  • @Trevex-UnKown
    @Trevex-UnKown 7 місяців тому +1

    Thank you for the tutorial and the explanations it was really helpful!

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

    Brilliant. This video really helped me out. Keep it up!

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

    Great! Thankyou! :)

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

    so it's that easy, huh?
    great video, very quick to show how to make it work

  • @AdamsAGD
    @AdamsAGD Місяць тому

    my nav mesh is saying it needs a bunchof stuff, only problem is my ground is a plane and when i try to give a collisionshape3d it wont let me use a plane, so i just put in a box and try to bake it and it crashses..

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

    Your videos are f#cking amazing.

  • @wowanimallia
    @wowanimallia 25 днів тому

    my enemy gets stucked after moving to a certain positon
    my enivironment is simple plane

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

    too bad look like it not working in stable 4.0
    Invalid call. Nonexistent function 'get_next_location' in base 'NavigationAgent3D'.

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

      it changed to get_next_path_position()

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

    Great tutorial! Can you do a tutorial for voxel terrain?

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

    Im having a nonexistent function problem with 'set_target_location'

  • @lukeaaron6946
    @lukeaaron6946 2 місяці тому

    Used this video to get avoidance working in my game. Thank you!

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

    great tutorial

  • @xxgafasdestroyer25xx56
    @xxgafasdestroyer25xx56 7 місяців тому +1

    My enemies are not moving, in code its says it moves but it dosent. What can i do?

    • @user-xsn5ozskwg
      @user-xsn5ozskwg 6 місяців тому

      How can you tell the code is telling the enemies to move? Is it possible you're missing the move_and_slide method?

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

    Thank you! You just saved a lot of hassle for me when it comes to pathfinding

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

    literally lost at the first step
    what is the environment node?
    the tutorial i was following has a level setup with a staticbody3d and meshinstance3d for visual and collisionshape3d for collision
    and i cant bake a nav mesh from that?

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

      seeing all the other comments asking the same question
      guess ill just find another tutorial

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

    Thank you so much :D

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

    Thank you very much!!!

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

    The move_toward solution is what I needed to solve a problem I have had for ages, thank you for the suggestion

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

    Perfect and concise intro to this functionality. Thanks!

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

    My enemy doesn't move at all ._.
    It just stays string at me
    (I used an anímated sprite 3d instead of a mesh instance 3d

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

    SO USEFULL THANKS

  • @jeaninemadrid752
    @jeaninemadrid752 3 місяці тому +1

    extends MeshInstance3D
    var SPEED = 3.0
    func _physics_process(delta):
    @onready var nav_agent = $NavigationAgent3D
    func update_target_location(target_location):
    nav_agent.set_target_location(target_location)
    var next_location = nav_agent.get_next_location
    var new_velocity = (next_location - current_location).normalize() * SPEED
    var current_location = global_transform.origin WHAT AM I DOING WRONG?!?!?!

    • @TheCommandBox
      @TheCommandBox 3 місяці тому +1

      Godot 4.1 release made some changes to NavAgent , look at first comment to fix the

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

      uh, u used mesh instance? or just the script is in it?

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

    anyone know how to make the enemies rotate towards you

  • @memze1148
    @memze1148 2 місяці тому

    Can someone help me before my head explodes, so my ai just moves forward to where I am but doesn't follow me, why is that?
    #this is my target code
    extends CharacterBody3D
    var health = 100
    var speed = 4.0
    @onready var nav_agent = $NavigationAgent3D
    # Called every frame. 'delta' is the elapsed time since the previous frame.
    func _physics_process(delta):
    # AI movement
    var current_location = global_transform.origin
    var next_location = nav_agent.get_next_path_position()
    var new_velocity = (next_location - current_location).normalized() * speed
    velocity = new_velocity

    # Update velocity
    velocity = velocity.move_toward(new_velocity, 25)
    move_and_slide()
    # Death
    if health

    • @memze1148
      @memze1148 2 місяці тому

      fixed it, I wasn't referencing the node properly.

    • @code-nk
      @code-nk 24 дні тому

      @@memze1148 help me out ...please

  • @Dignelson
    @Dignelson Місяць тому

    Thank you so much mate!

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

    Crazy good tutorial! Thank you!

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

    THANK YOU SO MUCH

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

    can someone please tell me whats wrong with ths code ts not working :/
    extends Node3D
    @onready var player = $Player
    func _physics_process(delta):
    get_tree().call_group("enemies", "update_target_position", player.global_transform.origin)
    extends CharacterBody3D
    @onready var nav_agent = $NavigationAgent3D
    var SPEED = 3.0
    func _physics_process(delta):
    var current_location = global_transform.origin
    var next_location = nav_agent.get_next_path_position()
    var new_velocity = (next_location - current_location).normalized() * SPEED

    velocity = velocity.move_toward(new_velocity, .25)
    move_and_slide()
    func update_target_position(target_position):
    nav_agent.set_target_position(target_position)

  • @srers357
    @srers357 Місяць тому

    in my project bluds just standing there not moving

    • @code-nk
      @code-nk 24 дні тому

      were you able to solve it

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

    Thank you so much dude, you've helped me a lot!

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

    Thank you!

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

    Does anyone know how to make a ai where if it's in range it will chase otherwise it will look around

  • @KumokoChan
    @KumokoChan 11 місяців тому +2

    Can you bake the NavMesh in script? For like, a procedural terrain.

  • @AlexRamoneLikeWhat
    @AlexRamoneLikeWhat 4 місяці тому

    i get this error:
    Invalid operands 'Vector3' and 'float' in operator '+'.
    anyone know how to help?

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

      you can't add a Vector3() to a float.

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

    Great Tutorial! You would make it more easy if you gave access to the test world files :)

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

    I was experiencing an error on var new_velocity = (next_location - current_location).normalize() * speed
    I dont know how fix it

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

      .normalized() dont forget the 'd'

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

    My enemy just yeets himself off the map and continues to go forever im at a loss. Can anyone help?

    • @user-xsn5ozskwg
      @user-xsn5ozskwg 6 місяців тому

      Your target location might be wrong. If you're following this tutorial exactly make sure that in the _physics_process method of the world script you correctly reference the player and their location (lines 3 and 6 at 6:20 in the video)

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

    anyone know what they changed _physics_process(delta) to?

    • @user-xsn5ozskwg
      @user-xsn5ozskwg 6 місяців тому

      That method still has the same name, what issues are you having?

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

    I LOVE YOU 💞💞💞💞💞💞💞💞💞💞💞💞💞💞

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

    For some reason it says delta is never used in the function which sounds like it doesn’t make any sense

    • @user-xsn5ozskwg
      @user-xsn5ozskwg 6 місяців тому

      If you never call delta it will be unused. It shouldn't cause any actual errors but to clean up your output add an underscore (the "_" symbol) in front of the parameter.

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

    For some odd reason, my "current_location" and "next_location" are always the same and as a result my enemies never move. My code is practically the same as in the video. I'm using Godot 4.0.2 stable. I can show my code and what not if need be

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

      Nevermind lol! Turns out it was the "Agent Height Offset" that was the problem

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

    The only thing this tutorial is missing is that sometimes the player may exit the NavigationRegion3D. When this happens the game lags out unbearably so.

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

      Thanks, I didnt know what was going on...

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

    doesnt work :(

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

    What about rotation?

  • @GamingsMostAmazingSoundtracks

    Yo dude the NavigationAgent3d node is gone in my current version. Is it now called something else

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

    its good and all and I appreciate the tutorial however how am I supposed to rotate the enemy towards the player

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

      I don't know if this is the best way, but you can use the look_at method. In the example in this video I think if you put look_at(next_location) in the _physics_process function it should work.

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

      @@mattvonfat Thank you I'll try it and see if it works , regardless if did or not I appreciate your reply fam :)

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

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

    What icon is that environment node? I dont see anything like that in 4.0.2

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

    I kepp getting the _physics_process() "delta" error

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

    Joka = 🌳

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

    Can i give you a positive criticism?
    When i need to learn something and i find a tutorial where the creator goes like "we will do this, but i will explain what this is for later", i usually will inmediately start looking for another tutorial because i would rather stop the tutorial for a couple of minutes to learn what that thing is before countinuing doing stuff because from that point i no longer understand what i am doing

  • @OmarSalha-j7h
    @OmarSalha-j7h 5 місяців тому +1

    Very nice video, but change that keyboard 😅

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

    E 0:00:00:0498 monster.gd:9 @ _physics_process(): NavigationServer map query failed because it was made before first map synchronization.
    Condition "map_update_id == 0" is true. Returning: Vector()
    modules/navigation/nav_map.cpp:119 @ get_path()
    monster.gd:9 @ _physics_process()

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

      Having same issue😢

  • @guillermoantonioventuragon1576

    Hello, for some reason when I try to enter nav_agent.get_next_path_location() It gives me an error: Invalid call. Nonexistent function 'get_next_path_location' in base 'NavigationAgent3D'. What am I missing?

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

    target reached did not work until I added this below 'var SPEED = 3.0'
    func _ready():
    nav_agent.connect("target_reached", Callable(self, "_on_navigation_agent_3d_target_reached"))
    Thanks GPT 4 ;)