Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Finding parts within a given radius/diameter?

Asked by 8 years ago

Hi. I've looked through the wiki and many questions asked here on SH, yet I haven't found the answer(s) I'm looking for. What I'm trying to do is retrieve all the 1x1x1 parts on a 2D plane within a given radius of another 1x1x1 part, but in a circular area. I'm sure there's a way to do this but I cant figure it out. Any help is greatly appreciated.

Thanks, -AwsomeSpongebob

P.S. Just to be clear, I'm not asking for a 10000 line script to be done for me (unless that's what it takes), just a few lines of code and an explanation on how it functions/what it does, etc. Thanks.

1 answer

Log in to vote
0
Answered by 8 years ago

One way of going about it would be to weld a sphere or cylinder to the part, like so:

-- Assume 'Part' is the part you want to check.
local RadiusPart = Instance.new("Part", workspace)
RadiusPart.FormFactor = "Ball"
RadiusPart.CanCollide = false
RadiusPart.Transparency = 1
RadiusPart.Size = Vector3.new(0, 0, 0) -- Change as necessary.
local Weld = Instance.new("Weld", Part)
Weld.Part0 = Part
Weld.Part1 = RadiusPart

Then, creating a table to hold the parts:

local PartsInRadius = {}

And hooking up events to RadiusPart causing it to: - Add a part to the table when touched. - Remove a part from the table when it stops being touched. Of course, you would want to check if the part was already in the table, so you don't add the same part twice.

Unfortunately, this method only works with parts which have the script in, and results in many more parts, but hopefully it is helpful.

0
Very helpful. Thanks. :) AwsomeSpongebob 350 — 8y
Ad

Answer this question