Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How could I get a Region3 of a rotated part? [SOLVED]

How could I get a Region3 of a part rotated by multiples of 90? I've tried everything, and I don't think using a premade module is necessary.

This is what I have for finding the Region3 of a 0,0,0 orientation part

local Region3 = Region3.new(Part.Position - (.45 * Part.Size), Part.Position + (.45 * Part.Size))

Thanks in advance,

Tim

Answer:

local Region3 = Region3.new(Part.Position - Vector3.new(.45 * Part.Size.Z, .45 * Part.Size.Y, .45 * Part.Size.X), Part.Position - Vector3.new(.45 * Part.Size.Z, .45 * Part.Size.Y, .45 * Part.Size.X))

1 answer

the easiest way is to simply get two opposite corners of the part using CFrame and then use math.min and math.max to turn those corners into a "max" corner and a "min" corner

the page for Region3 on the API documentation explicitly specifies that corners being "min" and "max" corners is important, so you can't just directly pass c1 and c2 to Region3.new()

local c1 = (part.CFrame * CFrame.new(-part.Size/2)).p
local c2 = (part.CFrame * CFrame.new(part.Size/2)).p

-- i like to split longish or repetitive operations like this into multiple lines, just makes it easier to read
local min = Vector3.new(
	math.min(c1.X, c2.X),
	math.min(c1.Y, c2.Y),
	math.min(c1.Z, c2.Z)
)
local max = Vector3.new(
	math.max(c1.X, c2.X),
	math.max(c1.Y, c2.Y),
	math.max(c1.Z, c2.Z)
)
local region = Region3.new(min, max)

2 comments

0

Thank you, I will test this when I am home.

0

Not exactly what I needed. Thank you though.

This discussion is preserved as it was. New answers, comments, and votes are closed.