Hello! In this video you can see the color blue which is the LEFT surface of the wedge and green which is the RIGHT surface. While moving my nodes around, you can see the wedge flips upside down. I’m using Egomooses triangle function. Does anyone know how I can prevent the flipping?
function service.drawTriangle(a,b,c,w1,w2)
local ab, ac, bc = b - a, c - a, c - b
local abd, acd, bcd = ab:Dot(ab), ac:Dot(ac), bc:Dot(bc)
if (abd > acd and abd > bcd) then
c, a = a, c
elseif (acd > bcd and acd > abd) then
a, b = b, a
end
ab, ac, bc = b - a, c - a, c - b
local right = ac:Cross(ab).unit
local up = bc:Cross(right).unit
local back = bc.unit
local height = math.abs(ab:Dot(up))
w1.Size = Vector3.new(THICKNESS, height, math.abs(ab:Dot(back)));
w1.CFrame = CFrame.fromMatrix((a + b)/2, right, up, back)
w2.Size = Vector3.new(THICKNESS, height, math.abs(ac:Dot(back)));
w2.CFrame = CFrame.fromMatrix((a + c)/2, -right, up, -back)
local modifier = ((w1.CFrame * CFrame.new(-1,0,0)).Position.Y < w1.Position.Y) and 1 or -1
w1.CFrame *= CFrame.new(modifier * -THICKNESS/2,0,0)
w2.CFrame *= CFrame.new(modifier * THICKNESS/2,0,0)
return w1, w2
end
My primary goal is to fix this issue. Switching the plugin on and off you can see the nodes are generated to the edges. If the triangle is in the wrong direction when the nodes are generated, the triangle positions itself lower than what its suppose to be. My guess is the flipping wedges are causing it?
This is my function that positions the nodes to the wedge points.
function service.linkNode()
local function offset(wedge,size,height)
return wedge.CFrame * CFrame.new(wedge.size.x/height,wedge.Size.y/size,wedge.Size.z/size)
end
for t,triangle in ipairs(CollectionService:GetTagged('Triangle Terrain')) do
local configuration = triangle:FindFirstChild('Configuration')
if configuration then
local wedge1,wedge2 = triangle.Wedge1,triangle.Wedge2
local node1 = createNodePart(triangle)
node1.CFrame = offset(wedge1,2,2)
local node2 = createNodePart(triangle)
node2.CFrame = offset(wedge1,-2,2)
local node3 = createNodePart(triangle)
node3.CFrame = offset(wedge2,-2,-2)
end
end
end