Need help making a grid-based pathfinding system which considers walls

Currently my pathfinding system recognizes tables, so a customer doesnt get up on them.
But not for walls. These walls are basically placed between tiles. I have no idea for this.
I tried adding a table which says directions towards near walls to the tile 2D array, and it ended up discovering that I cant check whether any Vectors, Lists and something like that are the same, or do things like finding them from a table because theyre instances.
Any help would be appreciated!

1 Like

vectors and lists are objects, and i think lua compares them by reference (same memory location)

but you can write your own function to compare them and vectors also have the FuzzyEq method

and can you share how your pathfinding system works specifically or the code; nobody can help without knowing how it works

You could try to store in every single tile an index of the neighbouring tiles it is connected to, so instead of checking all the neighbouring tiles the algorithm will only check the ones that are connected to it (AKA has no wall between them).
Edit: this is not a very optimized solution but it works

Currently I’m mobile so I can’t show you my (spaghetti) code but I’ll do my best explaining it.

gridmap(2d table) is looks like this

{
    [1] = {
         {
             Walls = {} -- list of vector2s
             Type = "Air" -- or "table", "chair"...
         }
         ....
    }
    [2] = {...}
}

Down below is pseudocode of the pathfinding function

function FindPath(plot, start: vector2, goal: vector2)
    it receives tycoon plot data as input
    so it can get its grid map (2d table)

    pathfinding algorithm is Astar
    openset is a priority queue
    (i used heap to sort it)

    while openset:IsntEmpty:

        currentVec = openset.pop

        if currentVec == goal:
            return path

        for its each neighbor: (top left right bottom)
            if theres wall between the neighbor:

                continue or add some cost
                this is the problem that I said
                I cant find a way to detect wall

            elseif neighbor is not air
                it is tables or something else ignore it

            else
                update and add it to openset

    cant find a path!!!

Currently my temporary solution is using tostring().
This enables me to find & index Vectors more easily.

+Edit: I found a problem that this makes β€œ-0, 1” and β€œ0, 1” different.
It works fine when I make -0 to 0.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.