How to get the corners of a face

How would I find the corners of any face I choose on a part?

Like if I choose the top face I would get all the positions of the corners on the top of the part.

The top front right, top front left, top bottom right, and top bottom left.
coners

You should search on the forum before posting,

local function getAxisFromValue(value: number): Enum.Axis
	for _, axis: Enum.Axis in Enum.Axis:GetEnumItems() do
		if axis.Value == value then
			return axis
		end
	end
	error("No Axis EnumItem with this Value exists.")
end

local function getFaceCorners(part: Part, normalId: Enum.NormalId): {Vector3}
	local cornerPoints: {Vector3} = {}

	local normalAxisValue: number = normalId.Value % 3
	local normalAxis: Enum.Axis = getAxisFromValue(normalAxisValue)
	local otherAxis1: Enum.Axis = getAxisFromValue((normalAxisValue + 1) % 3)
	local otherAxis2: Enum.Axis = getAxisFromValue((normalAxisValue + 2) % 3)	
	for dir1Sign: number = -1, 1, 2 do
		for dir2Sign: number = -1, 1, 2 do
			local localSpaceCorner: Vector3 = .5 * (
				part.Size[normalAxis.Name] * Vector3.FromNormalId(normalId)
				+ dir1Sign * part.Size[otherAxis1.Name] * Vector3.fromAxis(otherAxis1)
				+ dir2Sign * part.Size[otherAxis2.Name] * Vector3.fromAxis(otherAxis2)
			)
			local worldSpaceCorner: Vector3 = part.CFrame * localSpaceCorner
			table.insert(cornerPoints, worldSpaceCorner)
		end
	end
	return cornerPoints
end

@Entildo , the thread you linked is about finding every corner of a part. The OP of this thread wants to find the corners of a spesific face.

2 Likes

well thats only for the entire part, I want a face

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.