Get Part size relative to CFrame

Hi, I am having a problem where I want to get a parts size relative to a CFrame. It sounds complicated (it might be) but here are some images showing my problem.

Lets say the big part is A, and the small part is B, when B rotates, how would I get the size of A in B’s object space?

image
After rotated 90 degrees (The faces are an example of what part B sees as the front faces of the two, but B still has it’s front pointed in the same direction as the last image, as shown by the Vectors I drew)

In this case, the normal A’s size is 5,1,4 and A’s size in the second image is 4,1,5. How could I calculate this?

Can you try this

local function GetSizeRelativeToCFrame(partA, partB)
	local relativeCFrame = partB.CFrame:ToObjectSpace(partA.CFrame)
	local relativeSize = relativeCFrame:VectorToWorldSpace(partA.Size)
	return Vector3.new(math.abs(relativeSize.X),math.abs(relativeSize.Y),math.abs(relativeSize.Z))
end

This gets the relative cframe of PartA and PartB then rotates the size by the Cframe.

2 Likes

Thank you, this worked perfectly!

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