How to get adjacent Parts to a part without part:GetTouchingParts()

Ok so, I’m trying to make a Civilization Style unit movement system.

What I’m trying to do is get adjacent parts to a part.

The problem is, I’m using BasePart:GetTouchingParts(), but that only gets part if they are intersecting, and I don’t want to make my parts intersect when I’m using this function.

Is there another good way to get adjacent parts from 1 part Instead of using BasePart:GetTouchingParts()? The only solution i have is assign a value to each part, and if they are in the same range, Use it.

My script:(my codes kinda messy)

function gettouchingparts(part)
	    local connection = part.Touched:Connect(function() end) -- needs a touch interest
     local parts = part:GetTouchingParts() -- get touching parts
	     connection:Disconnect() -- remove connection
     return parts
local MovementTurns= 0
local allparts = {}
local touchingparts =part(script.Parent)
local lastcreatedtable = touchingparts

	MovementTurns= MovementTurns+1	
	local tableforparts= {}
	for i,v in pairs(lastcreatedtable ) do
		for k,j in pairs(gettouchingparts(script.Parent)) do
			table.insert(tableforparts, j)
			table.insert(allparts, j)
	lastcreatedtable = tableforparts
until  MovementTurns== 5

for i,v in pairs(allparts) do

Also Sorry for bad grammar

Yea, i was thinking about using Rays. But i never thought about region3. Thank you!

1 Like

you can size up the part and then get the intersecting parts and then size it down back to normal

One of the solutions you can try is, loop through every part that can be moved to and check the distance between them, this way you can know adjacent parts.

You can also use raycasting which I believe is way more practical.

I don’t know how expensive my method is to the code since it really depends on how many parts there are to move to.