TouchingParts() detecting the distance

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    Im making a build system where the part goes red if it touches an object and green if it doesn’t.
    Instead of going red as soon as the part touches an object I would like it to go red if it gets within a certain distance so I can allow for it to go slightly through the part.

  2. What is the issue?
    When I bring the client structure thats to be placed inside of a part it goes red I don’t want it to go red straight away I want it to go red only if it goes so far into the part

  3. What solutions have you tried so far?
    I tried finding all the touched parts then setting a distance the problem with this is it takes the distance from the centre of the part I need it to take the distance from the edge of the part.

function GetParts(struc)
	local overlap = OverlapParams.new()
	local IgnoreList = {clientStructure, workspace.Terrain}
	overlap.FilterDescendantsInstances = IgnoreList
	local TouchList = workspace:GetPartsInPart(struc, overlap)

	if #TouchList > 0 then

		for i,v in pairs(TouchList) do
			warn(v)
			if (v.Position - clientStructure.Position).magnitude < 4 then
			return true
			end
		end
	
	else 
		warn("NO PARTS TOUCHING!")
		return false

	end
end

You’ll most likely need to use raycasting to solve this problem. Here are some useful topics I found that should be helpful in explaining what you need to do:

1 Like