Add custom pathfinding obstacles alongside solids?

0 favourites
  • 6 posts
From the Asset Store
Obstacle Impacts and Cartoon voices, will makes your game more funny!
  • 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!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Bring the solids in 1 family ?

  • 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.

  • 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.

  • 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...)

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)