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.
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)
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.
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.