Help keeping parts inside a certain space

Hello. I have code from another forum post that gets the position of every corner of a part. This is needed because I need to keep a group of models inside a certain area. (I have already tried using region3, so don’t mention it!) The code works perfectly, other than the fact that it doesn’t support wedges.
image

The circled red dot is stopping the triangle from being able to move towards the left side of the plot. However, since this is a wedge we’re talking about, that red dot doesn’t even need to exist. How can I make that corner not count in the code since that is a wedgepart?

function getCorners(part)	
	local cf = part.CFrame
	local size = part.Size

	local corners = {}

	-- helper cframes for intermediate steps
	-- before finding the corners cframes.
	-- With corners I only need cframe.Position of corner cframes.

	-- face centers - 2 of 6 faces referenced
	local frontFaceCenter = (cf + cf.LookVector * size.Z/2)
	local backFaceCenter = (cf - cf.LookVector * size.Z/2)

	-- edge centers - 4 of 12 edges referenced
	local topFrontEdgeCenter = frontFaceCenter + frontFaceCenter.UpVector * size.Y/2
	local bottomFrontEdgeCenter = frontFaceCenter - frontFaceCenter.UpVector * size.Y/2
	local topBackEdgeCenter = backFaceCenter + backFaceCenter.UpVector * size.Y/2
	local bottomBackEdgeCenter = backFaceCenter - backFaceCenter.UpVector * size.Y/2

	-- corners
	corners.topFrontRight = (topFrontEdgeCenter + topFrontEdgeCenter.RightVector * size.X/2).Position
	corners.topFrontLeft = (topFrontEdgeCenter - topFrontEdgeCenter.RightVector * size.X/2).Position

	corners.bottomFrontRight = (bottomFrontEdgeCenter + bottomFrontEdgeCenter.RightVector * size.X/2).Position
	corners.bottomFrontLeft = (bottomFrontEdgeCenter - bottomFrontEdgeCenter.RightVector * size.X/2).Position

	corners.topBackRight = (topBackEdgeCenter + topBackEdgeCenter.RightVector * size.X/2).Position
	corners.topBackLeft = (topBackEdgeCenter - topBackEdgeCenter.RightVector * size.X/2).Position

	corners.bottomBackRight = (bottomBackEdgeCenter + bottomBackEdgeCenter.RightVector * size.X/2).Position
	corners.bottomBackLeft = (bottomBackEdgeCenter - bottomBackEdgeCenter.RightVector * size.X/2).Position

	return corners
end

Please ask questions if this doesn’t make sense, because I want a solution quick.

I was not really thinking, was I?
Sometimes writing about the code gives me the answer.

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