Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.01 KB | None | 0 0
  1. function makeNodeGrid(x, y)
  2.     local nodesInRow = math.floor(x/3)
  3.     local nodesInLength = math.floor(y/3)
  4.     local totalNodes = nodesInRow * nodesInLength
  5.     local nodes = {}
  6.    
  7.     local model = Instance.new("Model")
  8.     model.Parent = workspace
  9.    
  10.     local node = Instance.new("Part")
  11.     node.Shape = "Ball"
  12.     node.Anchored = true
  13.    
  14.     for i=1,totalNodes+1 do
  15.         local newNode = node:Clone()
  16.         newNode.Parent = model
  17.         newNode.Size = Vector3.new(0.5,0.5,0.5)
  18.         table.insert(nodes, newNode)
  19.     end
  20.     local origin = nodes[1].Position
  21.     local previousPoint = nodes[1].Position
  22.    
  23.     for i,v in pairs(nodes) do
  24.             if math.fmod(i, nodesInRow) == 0 then
  25.                 v.Position = origin + Vector3.new(0,2,0)
  26.                 origin = v.Position
  27.                 previousPoint = origin
  28.             else
  29.                 v.Position = previousPoint + Vector3.new(0,0,2)
  30.                 previousPoint = v.Position
  31.             end
  32.        
  33.     end
  34.     local A1 = Instance.new("Attachment")
  35.     A1.Name = "Attachment1"
  36.     local A2 = Instance.new("Attachment")
  37.     A2.Name = "Attachment2"
  38.    
  39.     for i,v in pairs(nodes) do
  40.         local A1 = Instance.new("Attachment")
  41.         A1.Name = "Attachment1"
  42.         local A2 = Instance.new("Attachment")
  43.         A2.Name = "Attachment2"
  44.         local A3 = Instance.new("Attachment")
  45.         A3.Name = "Attachment3"
  46.         local A4 = Instance.new("Attachment")
  47.         A4.Name = "Attachment4"
  48.        
  49.         A1.Parent = v
  50.         A2.Parent = v
  51.  
  52.        
  53.         if nodes[i+1] ~= nil then
  54.             A3.Parent = nodes[i+1]
  55.         end
  56.        
  57.         if nodes[i+nodesInRow] ~= nil then
  58.             A4.Parent = nodes[i+nodesInRow]
  59.         end
  60.         if nodes[i+1] ~= nil then
  61.             if (nodes[i+1].Position - v.Position).magnitude <= 2 then
  62.                 local rope1 = Instance.new("RopeConstraint")
  63.                 rope1.Color = BrickColor.new("White")
  64.                 rope1.Visible = true
  65.                 rope1.Parent = v
  66.                 rope1.Length = 2.3
  67.                 rope1.Attachment0 = A1
  68.                 rope1.Attachment1 = A3
  69.             end
  70.         end
  71.        
  72.         local rope2 = Instance.new("RopeConstraint")
  73.         rope2.Color = BrickColor.new("White")
  74.         rope2.Visible = true
  75.         rope2.Parent = v
  76.         rope2.Length = 2.3
  77.         rope2.Attachment0 = A2
  78.         rope2.Attachment1 = A4
  79.     end
  80.    
  81. end
  82.  
  83. makeNodeGrid(55, 25)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement