About Pathfinder


#1

Hi, this is my first forum post. Sorry if my level of English is not very good, I use the Google translator.
I’m building my first game in Gdevelop, and the first scene is a town, with its houses and streets.
Apart from the player, I have to create other NPC characters that move around town, and go from one house to another.
I understand that the Pathfinder method is the best for this, but when creating the NPCs they stay in the place where I created them, they do not target the objective.
I attach a screenshot of the scene, where I point out the NPC’s place of origin and the destination house.
I also attach a screenshot of the code I have created.
Can someone tell me what is wrong?
Thanks in advance


#2

I’m sorry, this is the second attach file


#3

I see you use the variable herreria to deactive the pathfinding.

Where is you event to active the behaviour?


#4

Herreria “Smithy” is the destination building, and the sprite has activated the behavior as an obstacle in search of a route, I have read in a post that perhaps this behavior prevents the NPC from going to the object, so I deactivate it when starting the movement


#5

you deactivate the pathfinding, if variable herreria =0. so it wont move.
pathfindingObstacle is a different behavior then pathfinding.

if variable herreria is not 0 and luis does not move, check if you have a object called “object”, since this is your reference object for distance.
is your object supposed to be luis?
the whole distance +100 is a bit confusing.
why not move luis to house003.X() / house003.Y()?


#6

Ok, I have tried it, the problem is that there are several instances of the same object, how do I indicate which instance it should go to?
By taking the test, it have addressed the closest instance


#7

if you click on your object, you get its properties window to the left.
there you can give you instance a variable, that you can use, to refer to that specific instance.

to select it, you use its variable as condition:


#8

I have tried to do as you say, I attach a screenshot, but the NPC still does not move from the site


#9

Do you have move then 1 “house003Casa1” objects in your scene?
or Do you have move then 1 “luis” objects in your scene?

another thing:
Does luis also have the PathfindingObstacle behavior?
if yes, make sure, that he is not impassible.


#10

No, House3casa1 does not have to move, only the NPC luis has to move in the direction of House3casa1
And no, the NPC Luis doesn’t have the Pthdfinder obstacle behavior


#11

when the NPC Luis reaches house3casa1, I eliminate the NPC, because then, after a while, the NPC must return to its point of origin and I will create it again for the new route


#12

check the hitbox of house003casa1
luis will try to go to the origin point of the house, the topleft corner by default.
make sure that corner is not overlapping with another house that has the pathfindingObstacle behavior.

can´t think of anything more.
E:
is the ,house003 ROTATED?


#13

ok, I’m going to check that 2 houses do not overlap


#14

maybe you should try to put a door object in the street in front of the house, where the npc goes.
then move the npc to the door object, to make sure no obstacles are in the way.


#15

Yes, it worked, thank you, thank you very much