Advertisement
killerbrenden

Tweening Grid

Nov 23rd, 2020
1,322
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.35 KB | None | 0 0
  1. local function createTile(vec3, n1, n2, parent)
  2.     local newTile = script:WaitForChild("Tile"):Clone()
  3.     newTile.Position = vec3
  4.     local nameTS = "Tile"..n1..n2
  5.     newTile.Name = nameTS
  6.     newTile.Highlight.Visible = true
  7.     newTile.Parent = parent
  8.     local tween = tweenService:Create(newTile, gridInfo, {Size = Vector3.new(gS,0.05,gS)})
  9.     tween:Play()
  10.     tiles[#tiles+1] = newTile
  11. end
  12.  
  13. local function createGrid(floor, grid)
  14.     local xs = floor.Size.X
  15.     local zs = floor.Size.Z
  16.    
  17.     local xp = floor.Position.X
  18.     local zp = floor.Position.Z
  19.     local yp = floor.Position.Y
  20.    
  21.     local gridSize
  22.    
  23.     if not grid then
  24.         gridSize = 3
  25.     else
  26.         gridSize = grid
  27.     end
  28.    
  29.     local xVals = {}
  30.     local zVals = {}
  31.    
  32.     for zVec = zs, gridSize, -gridSize do
  33.         zVals[#zVals+1] = zVec
  34.     end
  35.    
  36.     for xVec = xs, gridSize, -gridSize do
  37.         xVals[#xVals+1] = xVec
  38.     end
  39.    
  40.     for n,xv in pairs(xVals) do
  41.         for i,zv in pairs(zVals) do
  42.             local newVec = Vector3.new((xp - (xs / 2)) + xv - (gridSize / 2), (yp * 2) + 0.05, (zp - (zs / 2)) + zv - (gridSize / 2))
  43.             createTile(newVec, n, i, floor)
  44.         end
  45.     end
  46. end
  47.  
  48. local function removeGrid()
  49.     for num = 1,#tiles do
  50.         coroutine.wrap(function()
  51.             local tween = tweenService:Create(tiles[num],tweenInfo,{Size = Vector3.new(0.05,0.05,0.05)})
  52.             tween:Play()
  53.             tween.Completed:Wait()
  54.             tiles[num]:Destroy()
  55.             tiles[num]=nil
  56.         end)()
  57.     end
  58. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement