How would I go on about connecting two parts on their faces?

So while making a tree generator I ran into the problem of connecting the parts. I want the bottom face of the branch to connect to the top face of the stem.

This is my current script:

wait(5)

local NewPart = Instance.new("Part")
NewPart.Parent = game.Workspace
NewPart.Anchored = true
NewPart.Size = script.Parent.Size
NewPart.Position = script.Parent.Position + script.Parent.CFrame.UpVector
NewPart.Orientation = Vector3.new(math.random(0, 25), math.random(0, 25), math.random(0, 25))

And this is the outcome: (rotation of the seconds part is randomized)

I could not find a solution anywhere! I hope someone can help.

It looks like you’re not multiplying the UpVector property, perhaps try this?

wait(5)

local NewPart = Instance.new("Part")
NewPart.Parent = game.Workspace
NewPart.Anchored = true
NewPart.Size = script.Parent.Size
NewPart.Position = script.Parent.Position + (script.Parent.CFrame.UpVector * 10)
NewPart.Orientation = Vector3.new(math.random(0, 25), math.random(0, 25), math.random(0, 25))

Or you could set the Part’s Position with an increasing Y value Vector

I tried it and this happens
image

Whoops that’s way too much LOL

Try decreasing the multiplier by 5 instead

Ok 6.7 worked perfectly! Now I just need to connect the faces somehow.
image

Why do you have this line? That’s going to orientate the part randomly, shouldn’t it be

NewPart.Orientation = script.Parent.Orientation

So it has the same orientation as the aprt you want to connect to?

I didn’t see that bit haha

I’m assuming he wants to make a tree generator that creates random orientation parts that connect to the main branch & other connected branches & vice versa

You’d probably need to mess around with the majority of CFrames and their Vector3 values, maybe getting the size or something relevant alone those lines so that the branches don’t go far too up or too low?

Mate just imagine a straight positioned & orientated tree, yeah that would be uncomfortable & cursed to look at

1 Like