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

Creating a Region3 around a Part for FindPartsInRegion3?

Asked by 6 years ago

I have this function that get an Object from the workspace and an integer value:

function GetLocalParts(Object, Range)
    ObjectPosition = Object:GetPrimaryPartCFrame()
--  Region = ?
    for i, v in pairs(game.Workspace:FindPartsInRegion3(Region, nil, 100))
        print(Parts[i].Name)
    end
end

What the function is supposed to do is create a Region3 with the radius as the Range value, but I have never worked with regions before and the wiki is not helping to understand.

Once it has created the Region, it will print all of the parts within it. How do I create the region?

0
you forgot "do" on line 4 xMicro_Canary 37 — 4y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

So a Region3 won't work perfectly with a "radius" because that would create a sphere and a Region3 is a 3D rectangular prism.

A Region3 is constructed with two vector3s to define one corner, and the other corner.

To create a "radius" like prism around an object, you will want to create corners above behind and to the left of the object and a corner below, in front of, and to the right of the object. Here's how I would do it. The way that this box is created, the coordinates of the points have to be smaller first, then large.

For example we create a box with corners (1,1,1) to (9,9,9). All points from (1,9,9) to (9,1,9) are contained in our box.

local object
corner1 = object.Position - Vector3.new(range, range, range)
corner2 = object.Positon + Vector3.new(range, range, range)
-- Luckily because of how the math works out, the coordinate of corner 1 are always lower.
local region = Region3.new(corner1, corner2)
Ad

Answer this question