I am making a script that relies on knowing which parts are touching a certain part. I have made an image that helps further explain what I’m trying to achieve:
You can do this by constantly checking the magnitude of the two parts to see if they are touching. But it could be done another way considering what the actual situation is. are either of these parts cancollide off?
I’m making a fire spreading script and I need to find all the parts touching a part on fire, then making those touching parts on fire. Also, all the parts have CanCollide set to true.
If get touching parts isnt working then the only way I can think of doing this without usint extremely complicated math is to make a region3 box that is .01 studs bigger in all directions then the part on fire and then getting all the parts in the region3.
I just benchmarked it and creating a region 3 and searching for parts in it take about 26 one hundred thousandths of a second (0.00025699997786433) seconds
The region variable is the box in the 3D space being created. the min Vector3 value is one corner of the part, and the max Vector3 value is the opposite corner of the part. After the position of the corners of the parts are found add Vector3.new(-.05, -.05, -.05) to the lower corner(minValue) and add Vector3.new(.05, .05, .05) to the top corner(maxValue). after you find the region the partsInRegion variable will return a table with the parts in the region. This is a good video to learn from: Advanced Roblox Scripting Tutorial #17 - Region3 (Beginner to Pro 2019) - YouTube
local params = OverlapParams.new()
params.FilterDescendantsInstances = {--[[If you want to detect the green one, you should put blue one in here, you'll get the idea]]}
params.FilterType = Enum.RaycastFilterType.Blacklist
local touchingParts = workspace:GetPartBoundsInBox(Part.CFrame, Vector3.new(Part.Size.X + .25, Part.Size.Y + .25, Part.Size.Z + .25), params)