Region3 Sizing and Positioning?

So I’m trying to make my Region3 generated part in the same position/ size as another part, but it wont turn out at all how I wanted it to be. Am I using vector3 wrong?

I’ve tried using this and understand that Cframes exist but don’t understand how to implement it nor if it would work. Region3

local region = Region3.new(Vector3.new(0,2,-12), Vector3.new(8,4,8)) --Position/ Size

local part = Instance.new("Part", game.Workspace)
part.Anchored = true
part.Size = region.Size
part.CanCollide = false
part.Transparency = 0.8

while true do
	wait()
	local partsInRegion = workspace:FindPartsInRegion3(region, part, 1000)
	for i, part in pairs(partsInRegion) do
		if part.Parent:FindFirstChild("Humanoid") ~= nil then
			print("Player found in region: ".. part.Parent.Name)
			print(part.parent.Name)
			local char = part.Parent
		end		
	end
end

Can somebody help me out with a reference code, I cant find much on this topic.

Yes I have done another post similar to this asking about Region3 detection, that works fine but I never actually ended up using Region3; so I didn’t encounter this.

1 Like

From the Region3 wiki:

Region3’s are created with two vectors min/max, not size/position. To use the size/position method, you need to put your region through the ExpandToGrid function.

region = region:ExpandTogrid(4)

ExpandToGrid is more used for terrain, and won’t create exact regions as the resolution value will round up/down the grid.

For a precise region, you should just create a region with min/max.

local min = Vector3.new(part.Position.X-part.Size.X/2, part.Position.Y-part.Size.Y/2, part.Position.Z-part.Size.Z/2)
local max= Vector3.new(part.Position.X+part.Size.X/2, part.Position.Y+part.Size.Y/2, part.Position.Z+part.Size.Z/2)
local region = Region3.new(min, max)
2 Likes

I appreciate this, however I’m kinda new to scripting. And stated earlier not knowing how to actually implement something like that.

So could you explain to me how I define where I want it. Position and Size wise? I’m struggling with that.

And after reading the wiki, I understand vector3 only marks the bounds of the part.

I would recommend that you use this code instead of dealing with ExpandToGrid. You should make a variable for which part you want the region3 to go over instead of using it’s current position/size vectors so then in the future you can move and resize the part without needing to mess with your code.

The code may look complicated, but its actually just simple but tedious. The position of a part is defined by it’s center, so to get the two min/max vectors to define the region, you just subtract/add half the size from the position on each axis.

5 Likes

I have zero Idea why this works, but it does! The RegionPart spawns at origin, however, it is detected in its desired area… so it works. Thank you

1 Like

Region3’s have a CFrame argument, and you can get position/rotation from there. The reason the part spawns at origin is because you’re only setting its size, not position.

RegionPart.CFrame = region.CFrame

But if you’re creating the region based off of an existing part instead of specified vector values then you won’t need to generate a new part to visualize the region as the reference part serves as the visualization.

3 Likes

you can’t CFrame a Region i tried it it said cframe cannot be assigned to