Someone else found the solution to this very issue, so I will share with you here.
Replace direction_to
with distance_to
.
Why? distance_to
returns a float while direction_to
returns a Vector2.
distance_to_destination = position.direction_to(path[0])
returns a Vector2. minimum_arrival_distance = 5
returns a int of 5. You can't compare Vector2 with Ints/Floats. It will lead to the game crashing.
The issue is related to this function:
func navigate():
var distance_to_destination = position.direction_to(path[0])
if distance_to_destination > minimum_arrival_distance:
move()
else:
update_path()
Before finding this solution, I tried an earlier solution with limited success. It was instead of replacing direction_to
with distance_to
, just replace the minimum_arrival_distance = 5
with minimum_arrival_distance = Vector2()
. This will mean we are comparing two Vector2. That will allow the game to run without crashing and also allow the guards to move around. But their movement is buggy and they all end up getting stuck in one destination node after moving about for about a minute or so.
So this is the reason why instead, have both distance_to_destination > minimum_arrival_distance
as floats as oppose to Vector2s.