About 'Moving Guards Part 2- get_simple_path()'!

In this video (objectives)…

1 Using get_simple_path 2 Making sure that pathfinding works no matter wher we put our destinations 3 Have the guard move along a pathfinding 4 Have the guard wait at their destinations 5 Troubleshooting guards getting stuck

After watching (learning outcomes)…

Have pathfinding and guard movement fully implemented

(Unique Video Reference: 13_HM_GDT)

We would love to know…

  • What you found good about this lecture?
  • What we could do better?

Remember that you can reply to this topic, or create a new topic. The easiest way to create a new topic is to follow the link in Resources. That way the topic will…

  • Be in the correct forum (for the course).
  • Be in the right sub-forum (for the section)
  • Have the correct lecture tag.

Enjoy your stay in our thriving community!

Is it just me but I think in this video there was too much new information about pathfinding and so much new variables. It’s hard to remember what variables were needed and what each one did without watching the video again. Maybe you could put a link to some documentation about pathfinding to help us understand it better?

That’s fair - there’s quite a bit of new information here. I’ll link the documentation in the video (it’s also here if you want to peruse it)

Essentially, here are the steps we took.

  1. Define a NavigationPolygon - this is the area that the pathfinding will work within
  2. Create an empty array called path
  3. Create some destination using Position2D
  4. Pull all of those destination positions into an array by getting all the child nodes of their parent
  5. Pick a random destination from that array
  6. Use get_simple_path() to create a path from the guard’s current position to that destination
  7. Path is an array of coordinates, so we move the guard to the first entry in that array
  8. We remove that first entry and move to the new first entry
1 Like

Hi Yann,
I seem to have run into a problem after I have finished this lesson my player no longer moves or turns to look at the mouse, I get this message in the outlook window.

I went back and followed the lesson again and copied your code but still not working, I am now very confused.
Can you or anyone please help.
Many thanks.

I fixed the problem, I had miss spelt the word Global! when naming the Global script but spelt it correctly when using it in all other scripts lol… that will teach me to double check all spelling before saving.:thinking::wink:

i got stuck on a run time error which i could not think the reason for it
in the navigate() when referring to path[0] i get the attached error


the suggestions in the Q&A of the lecture have not helped .

would like to some advice please

Thanks & Regards

It’s saying the path array is empty - make sure you’ve got some code in there that gets a new destination if there’s only one value in the path array and you should be good to go

Hi Yann.

Apologies for the necromancy on this thread but I’m running into precisely the same issue as Hanoch - I’ve taken the script from the git repo available and done a diff against the script file and my own, and they appear the same - I’ve even swapped the script from the git repo into my project folder and I still hit the zero size path array issue with that one. Very confusing. Any suggestions on where to start troubleshooting?



	var next_destination = possible_destinations[randi() % possible_destinations.size()]
	path = navigation.get_simple_path(global_position, next_destination.global_position,false)

Hi , My get_simple_path returns weird array, First and final positions are correct but all others seems to be in local coordinates

[(509.605347, 426.801117), (69, 608.5), (96.5, 728), (99.5, 805.5), (555, 833), (694.5, 862.5), (702.5, 810.5), (709.5, 589.5), (764, 567), (843, 572.5), (1062.5, 634), (1120, 605.5), (1023.506958, 448.233002)]

Hi Yaan,

My guards keep getting stuck on furniture or walls.

I have spent much time trying to debug the issue, but I just can’t find it.
Looked at:

Guards appear to turn while walking and hit a wall then back into it, they do a lot of 180’s trying to wiggle out of the stuck state.

Here are some screenshots.



This is fixed.

I changed all “position” to “global_position” and added “$Timer.stop()” to the make_path() func.

I have had the same error as Kbatchelor and Hanoch, and I wanted to know how to fix this. It has been getting frustrating, I haven’t been able to solve the bug for 6 days and I cannot continue the course. Thanks for your help!

1 Like

The problem is probably in your Tileset’s navigation setup, In Yann’s video, he only set navigation for “Floor1” only. But in your level, you might used both “Floor1” and “Floor2” at the same time.

Possible fix: Go to your tileset edit and set navigation for your “Floor2” (all tiles) and try again.

This worked for me, so I hope it could help.


really sorry i missed this thread for questions.
if anyone is still experiencing issues, best to pop a new post under the ASK category as they ping up as a question wating for a resulution.

again, apologies for totally missing this :frowning: