So, I’m trying to make some roofParts via script. I have been struggling for days to get it working, but it keeps rotating.
I have tried everything from
CFrame.lookAt()
to anything else…
What do I want to achieve?
I want to be able to make it scale / stretch only, not rotate around the topNode aka. the centrePart.
For more info, look at the gif down below:
https://i.gyazo.com/be71a82fcc91147689cfb0f789b7dd80.gif
local function generateRoof(depth, width, thickness, angleOfElevation, location, parent)
local partwidth0 = workspace.point1
local partwidth1 = workspace.point2
local height = 5
local heightpart = workspace.topNode
heightpart.CFrame = partwidth0.CFrame:Lerp(partwidth1.CFrame, 0.5) + Vector3.new(0, height, 0)
--RoofA.Position = PointC.Position + Vector3.new(0, (Distance between A & C (YAxis))/2, (Distance between A & C (ZAxis))/2)
--RoofA.Size = Vector3.new(math.abs(Distance between A & B (X Axis), 1, math.sqrt( (Distance between A & C (X Axis)^2 + (Distance between A & C (Y Axis)^2 ))
--RoofA.CFrame = CFrame.new(RoofA.Position, PointC.Position)
local part = Instance.new('Part', parent)
part.Anchored = true
local dist = (partwidth0.Position - heightpart.Position).Magnitude + 2 * height * part.Size.Y / (partwidth1.Position - partwidth0.Position).Magnitude
part.Position = (partwidth0.Position + heightpart.Position) / 2
part.Size = Vector3.new(depth, part.Size.Y, dist)
part.CFrame = CFrame.new(part.Position, heightpart.Position)
local part2 = Instance.new('Part', parent)
local dist = (partwidth1.Position - heightpart.Position).Magnitude + 2 * height * part2.Size.Y / (partwidth1.Position - partwidth0.Position).Magnitude
part2.Size = Vector3.new(depth, part2.Size.Y, dist)
part2.Anchored = true
part2.Position = (partwidth1.Position + heightpart.Position) / 2
part2.CFrame = CFrame.new(part2.Position, heightpart.Position)
--CFrame.lookAt(part2.Position, heightpart.Position)
--heightpart:Destroy()
end
game:GetService('RunService').Heartbeat:Connect(function()
local point1 = workspace.point1.Position
local point2 = workspace.point2.Position
local depth = math.abs(point2.X - point1.X)
local width = math.abs(point2.Z - point1.Z)
local q = workspace.NewRoof
q:ClearAllChildren()
generateRoof(
width,
depth / 2,
5,
30,
point1:Lerp(point2, 0.5),
q
)
end)