Fastest way of detecting whether two parts touch each other?

I am currently making a turn-based strategy game. Here is a map from the game:

All of the parts above touch the ones that are next to them, however, GetTouchingParts() function does not return anything when called on any of the parts.

I think the only way of achieving this is by me going through every 87 tiles one-by-one and manually create object values of touching parts, but that would be too tiring and take too long. What do you think I should do?

4 Likes

Parts are anchored? if so, GetTouchingParts() will return nothing.

I’ve seen someone with a solution for his, by adding a TouchInterest really short.

EDIT: found it

local function GetTouchingParts(part)
   local connection = part.Touched:Connect(function() end)
   local results = part:GetTouchingParts()
   connection:Disconnect()
   return results
end

local results = GetTouchingParts(workspace.PartA)
print(#results) --> 1

This is the thread:

4 Likes

Um you can just use raycasting… You can also just name them based on their coordinates or store them in a table based on their X,Y,Z. Makes the most sense considering theyre arranged in a square grid. Other methods arently really necessary or as reliable or as efficient.

1 Like

lol how couldn’t I think of that :smiley: Thanks, this method is indeed better.