Add custom pathfinding obstacles alongside solids?

Get help using Construct 2

Post » Wed Jun 29, 2016 5:23 pm

I'm making a game where the pathfinding of an enemy requires both solids and a specific object to be included as their pathfinding obstacles. Is there a way to include them together (preferrably without using the customs section)?

(I have to do this because there are multiple doors with 2 frames for Locked & Unlocked, and each have solid & non-solid properties, respectively. I wasn't able to have the pathfinding reset when that happens, so I have to use the Solids pathfinding property instead.)

Thanks in advance! :D
B
19
S
6
Posts: 33
Reputation: 1,288

Post » Thu Jun 30, 2016 12:32 pm

Bring the solids in 1 family ?
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Thu Jun 30, 2016 3:42 pm

@99Instances2Go Thanks for the reply! However, I am actually trying to get a door to be included into the custom Pathfinding group when it is Locked, and remove it when the door is Unlocked.

Here is the failed-attempt code:
imgur.com/D58hKb5

So the Animation frame 0 is the Locked animation, while frame 1 is Unlocked. And there are multiple doors in the game, so any help from here is very appreciated. :D
B
19
S
6
Posts: 33
Reputation: 1,288

Post » Thu Jun 30, 2016 4:34 pm

The easy way is to use (the default) solids. Doors & walls must be solid. Regenerate the map. Do this under 1 'trigger once while true.

Use 'Regenerate region around object (the door) when its frame changed (close AND open). And ofcourse, after you changed its 'solid state'. It will reconize the changed 'solid state' and adjust the obastacles arround the door.

Be aware that the obstacle map is ready the next tick (NOT this tick). So, the 'find path' you can do at the start of the event sheet.
The 'on path found' you can set wherever you want. But, i dont see it in the pict. So i have no idea how often you force it to find a new path. Cant be done to often, because then all it does is search, and before a path is found, it will be searching again.

The way you do it, all obstacles all over again, it can take quite some time to generate the obstacle map. And you probaly found a path before the obstacle map is ready.

Also, there is ONLY ONE obstacle map. So setting new obstacles for one pathfinding object will change the obstacle map for all. So, dont use a 'for each' to set obstacles for all pathfinding objects.

So what do you do wrong? I can guess, but i have no idea. I dont see the layout. Is the door to small compared to cellsize and cellborder? Did you forced it to look for a path before the obstacle map was ready ? Do you force it to find a path to often ? Are the collision polygones weird ? But i suppose, with those tips you can solve it.

If you want to be sure, start a timer on the moment you regenerate the obstacle map (like 0.2 secondes). And when the timers goes off, let it find a path.

Hope this 'rambling in the dark' helps you some.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Fri Jul 01, 2016 4:55 pm

Thanks for the reply, @99Instances2Go ; I actually tried that, but the enemy sprites keep overlapping the walls & doors (for no reason) when moving along their path(s). Is there a way to prevent this from happening, eg cell size, cell border, adding stuffs in, etc?

NOTE: The enemies' resolution are 48 x 48, and has collision polygons of a square of the same resolution: imgur.com/a/oNLlC
(Ignore the green tiles - they're there for some unknown reason...)
B
19
S
6
Posts: 33
Reputation: 1,288

Post » Fri Jul 01, 2016 10:40 pm

Pathfinder does not keep objects out of the solids. It just finds paths. You have to try to make it find paths that stay enough away from the solids. For that you need to tweek the Cell size & the Cell border.

https://www.dropbox.com/s/g726tpvjzxqul ... .capx?dl=0

Look @ the grid, cell size, border and look @ the invisible things.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950


Return to How do I....?

Who is online

Users browsing this forum: TRMG and 31 guests