[SOLVED] Force Pathfinding to use previous one

Hi, i’m on a project of a Tower defence like game with random enemy’s spawner.

I’m trying to work on the way to set up a path for Enemies with the Pathfinding Behavior.
With the help of @ Keith_1357
I achieve a sort of drawing the path for the player being able to see it.

I’m now on another problem with the pathfinding behavior.

I would like the new enemy to take (when possible) pathfinding that have been previously draw.
I try to use a cost on floor or and the mask. but i can’t get what i want that way.
Here is the mask


And here thr draw that allow a special floor to be reveal on Enemy’s path.

When i set up a turret (not on the path but near it) the pathfinding change to avoid it.
I would like the “hitbox” if this change be smaller or Telle the pathfinding that it cost more to draw a new path than taking an existing one.

here is what happend.
Pathing

I’m open to any solution or another extension to help me in this situation.
Thanks

I think I understand what you’re saying. You want them to take an existing road. Let me think about it.

Do you have a pathfinder obstacle behavior on the guns? If so, maybe try adding a separate object that is just the size of the base of the structure and use it as the obstacle instead of the entire gun. Think of it in a 3D perspective. Ony the base isn’t passable.

Just for clarity only the spot where the arrows are pointed are unpassable. Maybe a little taller to take into account the depth of the base.
image

Hello again ,
My turret are split in half, i’m sure that the head (the rotating part) don’t have the obstacle behavior, and i’m pretty sure (i’m not at home right now) the base don’t have it either.

I think this problem will also come up with multiple obstacle, what would really solve the problem for me would be a way to “reward” or at least don’t increased the cost of enemy by making them using already draw pathfinding / mask off.

The way you explain to me (about the road being revealed when they pathfind it) i think i could make an obstacle behavior on the mask and make it cost 2, thinking it was going to be easier for use place where mask was off.

But it didn’t go that way, pathfinding was creating a new path for every enemy, creating a weird maze of pathing, and i don’t get what it happend.

It’s not very clear and i can’t make screenshot for now.

Because at the end, in the game the player will be able to change de pathing of enemy by blocking them with turret, but i would like it to be predictible for him (the player) and the way it’s working now is pretty randomi would prefer it, to dodge the obstacle then go back ASAP on already discovered pathfinding

You can’t assign paths, you can only put-up obstacles. The linked path finder uses objects to create a path. That does allow you to decide which tiles to use. It uses objects to find paths.

Okay, i found a partial solution, i make my turret not impossible to path, but cost 2, that way the enemy try to collide with a minimum of them.

I was thinking of something, could i just imput an invisible market on each square of my grid, when enemy collide with it , it delete it, and make it cost 1 to path through ?
That way it will be “cheaper” for the enemy to go where there is none ?

1 Like

Well i tried it, and it work pretty well, still not perfect, but enemy try to join a “free” way ASAP and avoid creating new path.
Pathing

For those who could be interesetd in the solution i used


I set up variable to make a grid
.


I make the grid here
.


Hide it (it’s ugly)
.


Here i delete the grid when enemy collide with it (don’t mind de scene Var here it’s just to print it on screen)
.


Here is the behavior for the grid make it cost 1.
That way enemy, will be able to cross the grid, but will try to avoid it.

New problem…
image
Can’t find a path

but here
image
They path through…

How can i solve this ? it look like there is a collisions or something that block the pathfinding…it’s driving me crazy.

@ Keith_1357 i hope you will be able to help me :wink:

Edit:
This is not a problem
image

But this
image
Disable the pathing

EDIT:Edit

image
It appear that the only “side” ta make the problem happend is the left side of each obstacle.
Un right, down and up the enemy can walk next to, and it’s not a problem

Ok, found it, the point of the object are the key, They need to be centered on the tile.

1 Like

Good to hear that you solved it. Just remember it uses the width and height not the collision mask. You can use a hidden smaller object as an obstacle for a larger image. It also doesn’t like rotated objects. It’s best to resize the object instead of rotating them. Otherwise it may ignore the object and go through it. It seems to use the unrotated size.