Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make 2 part's faces connect?

Asked by 5 years ago

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

0
do you want them to connect immediately, or to move to their final positions? SerpentineKing 3885 — 5y
0
Immediately Professor_Boxtrot 136 — 5y
0
would you be welding them? GoldAngelInDisguise 297 — 5y
0
No, I just want the position + angles (CFrame) Professor_Boxtrot 136 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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)
0
The whole question was how to actually calculate the cframe the green part needed to be at... Professor_Boxtrot 136 — 5y
0
I'm playing with the CFrame now, so I'll give a way to calculate in a bit SerpentineKing 3885 — 5y
0
The problem with calculating the cframe for this, is that this ONLY works for my example, I want something that works for any face. Professor_Boxtrot 136 — 5y
0
If you copy this code line for line, then yes it only works for your example, you'd have to alter the x, y, or z position values along with the orientation under your own function to create other "connections" SerpentineKing 3885 — 5y
0
That's literally what I made this question for... Professor_Boxtrot 136 — 5y
Ad

Answer this question