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/"
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.
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.
@@Gdquest looks like it has been removed from the Godot 4 Beta1 just released.
@@nathanwaterman4380do you know how to use it? I cant find a video.
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.
such original idea.. love it
This channel should be having more than 1 million subscribers
I feel like GDQuest is the Brackeys of Godot, but not enough people use Godot
@@lukeh5325 🤝 Agreed, l think Godot will grow overtime
Thank you so much for all your videos, really valuable information every time! :)
Thanks for all the great content. You helped me get started a lot.
Thanks!
Nice video keep up the good work GDQuest
Thanks for this tutorial 🙂 It worked for me
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?
Thanks for this guide, you the only one who tell about this pathfind system. I think you should have more likes and subscribers!
Thank you! 😁
Lifesaver. Thanks to you I can now win at my unis game jam
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.
3.5.1-rc1
@@alexanderstreng4265 ahhhh this might explain a thing or two... I'll have to update
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.
Great video! Is there an example for a platformer/sidescroller game?
Thanks for the video, and I have some different newbie question now: is there real profit for declaration variables with simple " = " or with " := "?
@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
But the A* is already implemented in the engine
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.
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.
Question, how would the new navigation system work when it comes to creating a patrol state for an enemy?
could you make a video how to make it work nicely with tilemap
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?
Will you guys cover the navigation system in 3d?
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...
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.
Is there a way to make this work with a tilemap?
hi a quistion how do i get player from a other scene with this ?
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.
Where can you set Edge Connection Margin in Godot 4 now that Navigation2D node is gone?
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??
Is there a method with low performance cost to check the distance between player and target on runtime?
global_position.distance_to() works fine no?
Will a similar method work in 3d?
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?
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.
@@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?
When I try to instance another enemy I get an error that reads "invalid get index 'global_position' (on base: 'null instance').
New question. How do I assign the path to player automatically when instancing a new enemy?
How can i learn godot efficient ply?
Ctrl click drag into auto typed var ? :O
How do i use pathfinding for a 2d platformer
How would u get this to work in Godot 4 beta 7
your video’s are amazing- can you help with a few tNice tutorialngs
_please _talk _about _how _to _do _neural _networks =D
That's not working, thanks
sa
last
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.
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.
@@Gdquest I said with different sizes. how would it work?
I'd like to see a video on Astar + grid movement 🥲
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.
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/
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)