Help with basic roof generation, resolving a small gap between 2 parts at top, is my formula the most effective?

Hello!

I’m no math genius so I am in a bit of need with this issue. Essentially, I am trying to create a basic gable roof, which is just 2 parts at a peak for right now. My problem is that there’s a small gap at the top and I am not sure how much bigger to make parts so it doesn’t happen.

Here’s my script, pretty basic. Feel free to try it out so you know what I’m talking about.

local partwidth0 = workspace.pw 
local partwidth1 = workspace.pw2
local height = 1

local heightpart = Instance.new('Part', workspace)
heightpart.Position = (partwidth0.Position + partwidth1.Position) / 2

heightpart.Name = 'HEIGHT'

heightpart.Position = Vector3.new(heightpart.Position.X, heightpart.Position.Y + height, heightpart.Position.Z)

height = heightpart

local part = Instance.new('Part', workspace)
local dist = (partwidth0.Position - height.Position).Magnitude
part.Position = (partwidth0.Position + height.Position) / 2
part.CFrame = CFrame.lookAt(part.Position, height.Position)
part.Size = Vector3.new(part.Size.X, part.Size.Y, dist)

local part2 = Instance.new('Part', workspace)
local dist = (partwidth1.Position - height.Position).Magnitude
part2.Position = (partwidth1.Position + height.Position) / 2
part2.CFrame = CFrame.lookAt(part2.Position, height.Position)
part2.Size = Vector3.new(part2.Size.X, part2.Size.Y, dist)

height:Destroy()

Here’s my problem:
There’s a small gap in the top which gets more apparent as the roof height gets taller.

1 stud height:

10 stud height
Capture d’écran, le 2020-10-21 à 18.35.36

100 stud height

I’ve tried writing a formula and this is what I came up with, but I was wondering if it was the most effective and accurate one:

length = magnitude + length + (16 / 360) * height

1 Like

Factor the part thickness into the equation. (thickness being part.Size.Y)

length = magnitude + 2*height*thickness/width

local dist = (partwidth0.Position - heightpart.Position).Magnitude + 2*height*part.Size.Y/(partwidth1.Position - partwidth0.Position).Magnitude
--ensure both parts use this dist

Btw, you might be better off sticking a cylinder through the top rather than resizing with the above method. The method you’re asking for has no solution when the the convex angle at the tip of the roof is less than 90 degrees.

2 Likes

Thanks!

You’re right about the cylinder thing, however I plan on using unions to get rid of that.

Hey, I based my system on your calculations but how I would rotate it?

Edit: I already figured out how so If you read this just ignore lol

3 Likes