I’m working on a Plugin and looking to implement a feature that’ll re-insert Nodes after a user removes them and finishes a session.
Currently my setup uses x2 Wedges to create a ‘Plane’ between 3 Nodes as depicted below.
How would I be able to find these exact three points of the Model once the Nodes have been removed and there’s no evidence of their previous whereabouts?
Any help will be greatly appreciated!
EDIT:
I’ve found a method of doing so, however when I apply it to pre-existing terrain it generates multiple versions of the same Node - Does anyone have any theory on how I can prevent this?
local Node = Instance.new('Part')
Node.Anchored = true
Node.Size = Vector3.new(1, 1, 1)
Node.Transparency = 0.5
--||--||--||
function getCorners(part)
local cf = part.CFrame
local size = part.Size
local corners = {}
local frontFaceCenter = (cf + cf.LookVector * size.Z/2)
local backFaceCenter = (cf - cf.LookVector * size.Z/2)
local bottomFrontEdgeCenter = frontFaceCenter - frontFaceCenter.UpVector * size.Y/2
local topBackEdgeCenter = backFaceCenter + backFaceCenter.UpVector * size.Y/2
corners.bottomFrontLeft = (bottomFrontEdgeCenter).Position
corners.topBackRight = (topBackEdgeCenter).Position
corners.bottomFrontRight = (bottomFrontEdgeCenter).Position
return corners
end
--||--||--||
for __,i in (Self.Parent:GetChildren(...)) do
if i:IsA('Model') then
local corners
local Wedge1 = i:FindFirstChild('Wedge1')
local Wedge2 = i:FindFirstChild('Wedge2')
if Wedge1 and Wedge2 then
corners = getCorners(Wedge1, ...)
local Clone0 = Node:Clone(...)
Clone0.CFrame = CFrame.new(corners.bottomFrontLeft)
Clone0.Parent = Self
local Clone1 = Node:Clone(...)
Clone1.CFrame = CFrame.new(corners.topBackRight)
Clone1.Parent = Self
corners = getCorners(Wedge2)
local Clone0 = Node:Clone(...)
Clone0.CFrame = CFrame.new(corners.bottomFrontRight)
Clone0.Parent = Self
end
end
end