I have 2 parts that I want their faces to connect (let's say in this instance I want part A to have it's face Top attached to part B's face Front)
Getting the position is fairly simple, it would just be part A's face * half of part A and B's size on the correct axis.
Making 2 faces line up is harder, and I've had no luck finding a way to do it.
Screenshot of what I want:
https://gyazo.com/849b281dd6741ffbe12ccf5c4543ce0a
Well my first thought on doing this, was to actually use Three Parts
, assuming that one of the "Parts", in this case the one with the Red Face, is stationary. You could clone the part with the Green Face and rotate and place it where it needs to go on the Red Face part, you can then make this part invisible (Transparency = 1) and noncollideable (CanCollide = false), at this point, the size of the third part would not matter either.
Next, you could create a Tween in order to move the part to the third part's CFrame, or just immediately move it to the place.
local TweenService = game:GetService("TweenService") local timer = 1 local tweenInfo = TweenInfo.new(timer) workspace.Part2.ClickDetector:MouseClick:Connect(function() local goal = {} goal.CFrame = workspace.Part3.CFrame local movable = workspace.Part2 local tween = TweenService:Create(movable, tweenInfo, goal) tween:Play() wait(timer) end)
In order to move it to the exact location
workspace.Part2.ClickDetector:MouseClick:Connect(function() workspace.Part2.CFrame = workspace.Part3.CFrame end)
Both of the above examples assume a click detector for the function to be enacted.
EDIT: Since you asked for an immediate transition, this should do the trick
local y = math.abs(workspace.Part2.Size.Y) workspace.Part1.CFrame = CFrame.new(workspace.Part2.Position + Vector3.new(0, y, 0)) workspace.Part1.Orientation = Vector3.new(0, 0, 90)
Part2 is the part with the RedFace and Part1 is the part with the GreenFace
If you want different rotations, you'll have to try out different degree values for the Orientation
The "Y" value is used to move the position a set amount from the original CFrame
Note: There is no function to weld decals or part faces directly, if you want multiple different positions, you'd have to copy this set of code and experiment.
Z-Variation
local z = math.abs(workspace.Part2.Size.Z/1.35) workspace.Part1.CFrame = CFrame.new(workspace.Part2.Position + Vector3.new(0, 0, z)) workspace.Part1.Orientation = Vector3.new(0, 90, 90)
X-Variation
local x = math.abs(workspace.Part2.Size.X) workspace.Part1.CFrame = CFrame.new(workspace.Part2.Position + Vector3.new(x, 0, 0)) workspace.Part1.Orientation = Vector3.new(90, 0, 90)