I got a problem a placing a part (variable name: “struct”) next to another part (“hit”).
Here are 3 parts, the blue part (hit) is the part i am aligning the grey part (struct) to:
For this i use a slightly modified version of the code i use to align boxes to wedges/triangles, Boxes are 10,10,10 in size, the grey part are 1,10,10:
local length = (Struct.Size.Z / 2 + Struct.Size.X / 2) -- or 5.5
newPos = (Hit.CFrame + (Hit.CFrame.RightVector * length)) * CFrame.new(0, 0, (10 - Hit.Size.Z) / 2)
I use the PivotTo and PivotOffset to rotate the parts, but thats not relevant here, as its not a problem.
What i do here is to get the RightVector then multiply it by the lenght, i.e. how far i want to be placed away from the centre of the Hit.CFrame position.
The problem is, i want the part to align to the red part, and whatever i do- modify the “length” modify the CFrame by say moving -5 studs in x direction, there always is a small misalignment of something like 0.01 - 0.05 studs.
Here in the picture above i have moved the CFrame -.5 in the z direction, this does not work. I have also tried getting the RightVector of the blue part (hit) and multiply it by .5, that does not either work.