Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can you tell what parts are adjacent to another part?

Asked by 10 years ago

I have a grid-based pathfinding setup, and I've just started working on the proper pathfinding part. I'm not sure how to tell which blocks are adjacent to my starting block without causing a major lag spike or taking too long to loop through all the parts.

my grid creater -

bricksize = 5

for i, v in pairs(Workspace:GetChildren()) do
    if v.Name == "Floor" then
        totalr = v.Size.X/bricksize
        totalc = v.Size.Z/bricksize
        r = 1
        c = 1
        for rr = 1, totalr do
            for cc = 1, totalc do
                p = Instance.new("Part", Workspace)
                p.Size = Vector3.new(bricksize, 1, bricksize)
                p.Position = Vector3.new(bricksize * c, 1, bricksize * r)
                p.Anchored = true
                count = count + 1
                c = c + 1
            end  
            r = r + 1
            c = 1
        end
    end
end

I'd give you the start of the pathfinding script, but it didn't save (or I forgot to save it) :(

Thanks for any advice you can give me.

Answer this question