Making a part depending on the other parts position

Hello! Does anyone know how I could make a part depending on the positions of the 4 parts that I have?

The red part of the image is supposed to be the part I want to create.
Any type of help I will appreciated.

This should be simple vector math.

I see the red part interests at the middle of these 4 green parts, therefore we can ignore their size and only worry about the origin point.

If the 4 parts make a true rectangle, you can use one opposite corner and ignore the other two.

The math will look something like this:

local vec1 = part1.Position -- let's say this is top left
local vec2 = part2.Position -- let's say this is bottom right

local diff = vec2-vec1
local size = Vector3.new(math.abs(diff.x), 1, math.abs(diff.z)) -- assuming part height of 1

3 Likes