The ultimate impossible coding problem! 99.99% cannot solve xd

Given two Vector3 values of the endpoints of a rectangular prisms diagonal, How do you create a part purely from a script that positions and sizes a spawned part to include the diagonal endpoint vertices?

The red parts are a representation of the given Vector3 values, and the gray box is what you are trying to create with purely scripting.

Its easy when these parts have no rotation, but what if its rotated on one axis? Two? Three? (Ordered left to right)

I spent 3 hours using my brain and chatGPT and could not find an answer. Maybe you are smarter :thinking:

Assuming you want the axes of the gray box to match those of the red corners:

local red1 = workspace.red1
local red2 = workspace.red2

local center = (red1.Position + red2.Position) * 0.5 
local cframe = red2.CFrame - red2.Position + center
local size = red1.CFrame:VectorToObjectSpace(red1.Position - red2.Position)
size = Vector3.new(math.abs(size.X), math.abs(size.Y), math.abs(size.Z))

local p = Instance.new("Part")
p.Size = size
p.CFrame = cframe
p.Anchored = true
p.Transparency = 0.5
p.Parent = workspace

im speechless…

wow man im dumb

look i’ve rotated a lot of cubes

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