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
end
local MovementTurns= 0
local allparts = {}
local touchingparts =part(script.Parent)
local lastcreatedtable = touchingparts
repeat
wait()
print(MovementTurns)
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)
end
end
lastcreatedtable = tableforparts
until MovementTurns== 5
for i,v in pairs(allparts) do
print(v.Name)
end
Also Sorry for bad grammar