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

Help with finding parts in a certain area?

Asked by 4 years ago
Edited 4 years ago

My code:

local region = Region3.new(Vector3.new(500, 200, -498), Vector3.new(-500, 12, 498))
local mapArea = Instance.new("Part", workspace)
mapArea.Anchored = true
mapArea.CanCollide = false
mapArea.Position = Vector3.new(0, 100, 0)
mapArea.Size = region.Size

I'm trying to find any parts in between those two points, but when my code is run, the part it makes is tiny, and a straight line. Then, I run the :FindPartsInRegion3(region, ,mapArea, 1000). Please help! Is there an easier way to do this?

0
GetTouchingParts returns a table filled with the parts touching the object, you can also use magnitude. greatneil80 2647 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

Region3's constructor requires a minimum and maximum vector. What it means by that is every coordinate in the minimum vector argument has to be less than the maximum. You could construct new vectors and take each coordinate of the original vectors and find the min/max of each

local function region3Vectors(vector1, vector2)
    local min = Vector3.new(
        math.min(vector1.X, vector2.X),
        math.min(vector1.Y, vector2.Y),
        math.min(vector1.Z, vector2.Z),
    )

    local max = Vector3.new(
        math.max(vector1.X, vector2.X),
        math.max(vector1.Y, vector2.Y),
        math.max(vector1.Z, vector2.Z),
    )

    return min, max
end

Then just add that to your region3 constructor

local region = Region3.new(region3Vectors(Vector3.new(500, 200, -498), Vector3.new(-500, 12, 498)))
Ad

Answer this question