Guest User

Script

a guest
Aug 12th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 18.16 KB | None | 0 0
  1. Here is the code, how would i make it so it goes up i can stack blocks.
  2. ~~~~~~~~~~~~~~~~~
  3. local INTERPOLATION = true -- whether placement smoothing is enabled
  4. local INTERPOLATION_DAMP = .21 -- how fast smoothing is, make it a value (0, 1]
  5. local ROTATION_SPEED = .2 -- rotation tween speed in seconds
  6.  
  7. local COLLISION_COLOR3 = BrickColor.Red().Color -- color of the hitbox when object collides
  8. local COLLISION_TRANSPARENCY = .5 -- transparency of the hitbox when object collides
  9.  
  10. local NORMAL_COLOR3 = BrickColor.new().Color -- color of the hitbox
  11. local NORMAL_TRANSPARENCY = .9 -- transparency of the hitbox
  12.  
  13. local LOAD_COLOR3 = Color3.fromRGB(226, 155, 64) -- color of the hitbox when loading
  14. local LOAD_TRANSPARENCY = .6 -- transparency of the hitbox when loading
  15.  
  16. local GRID_TEXTURE = "rbxassetid://13786085" -- texture of the grid space, set to nil if you don't want a visible grid
  17.  
  18. local OVERRIDE_CONTROLS = false -- whether click to place and r to rotate are enabled
  19. local INPUT_PRIORITY = 9 -- input priority of default controls
  20. local TOUCH_RANGE = 30 -- range of mobile placement
  21.  
  22. local PLACEMENT_COOLDOWN = .45 -- how quickly the user can place
  23.  
  24.  
  25. --[[
  26.     DO NOT EDIT PAST THESE LINES UNLESS YOU KNOW WHAT YOU'RE DOING 
  27. --]]
  28.  
  29. local module = {}
  30.  
  31. local player = game.Players.LocalPlayer
  32. local mouse = player:GetMouse()
  33. local runService = game:GetService("RunService")
  34. local touch = game:GetService("UserInputService").TouchEnabled
  35.  
  36. local currentPlane
  37. local currentBase
  38.  
  39. local renderConnection = nil
  40.  
  41. local cx, cy, cz, cr = 0, 0, 0, 0
  42. local currentObjects = {}
  43. local currentEvent
  44. local currentTexture
  45. local currentPosition = Vector3.new(0, 0, 0)
  46. local ax, az
  47.  
  48. local currentExtentsX
  49. local currentExtentsZ
  50. local currentYAxis
  51. local currentXAxis
  52. local currentZAxis
  53. local currentAxis
  54.  
  55. local ox, oy, oz -- do
  56. local dxx, dxy, dxz
  57. local dzx, dzy, dzz
  58.  
  59. local min = math.min
  60. local max = math.max
  61. local abs = math.abs
  62.  
  63. local springVelocity = Vector3.new(0, 0, 0)
  64. local springPosition = Vector3.new(0, 0, 0)
  65. local tweenGoalRotation = 0 -- springs arent worth effort for rotation
  66. local tweenStartRotation = 0
  67. local tweenCurrentRotation = 0
  68. local tweenAlpha = 1
  69.  
  70. local lastRenderCycle = tick()
  71. local lastPlacement = tick()
  72.  
  73. local function round(n, to)
  74.     return n % to ~= 0 and (n % to) > to/2 and (n + to - (n % to)) or (n - (n % to))   
  75. end
  76.  
  77. local function project(px, py, pz)
  78.     px, py, pz = px - ox, py - oy, pz - oz
  79.    
  80.     return px * dxx + py * dxy + pz * dxz, px * dzx + py * dzy + pz * dzz
  81. end
  82.  
  83. local function translate(px, pz, r)
  84.     if (r == 0) then
  85.         return px, pz
  86.     elseif (r == 1) then
  87.         return -pz, px
  88.     elseif (r == 2) then
  89.         return -px, -pz
  90.     elseif (r == 3) then
  91.         return pz, -px
  92.     end
  93.    
  94. --  or for all angles
  95. --  r = r * math.pi/2
  96. --  return math.cos(r) * px - math.sin(r) * pz,  math.sin(r) * px + math.cos(r) * pz   
  97. end
  98.  
  99. local function angleLerp(a, b, d) -- to avoid angle jump
  100.     local x1, y1 = math.cos(a), math.sin(a)
  101.     local x2, y2 = math.cos(b), math.sin(b)
  102.    
  103.     return math.atan2(y1 + (y2 - y1) * d, x1 + (x2 - x1) * d)
  104. end
  105.  
  106. local function calculateExtents(part, cf)
  107.     local cf = cf or part.CFrame
  108.    
  109.     local edgeA = cf * CFrame.new(-part.Size.X/2, 0, 0)
  110.     local edgeB = cf * CFrame.new(part.Size.X/2, 0, 0)
  111.     local edgeC = cf * CFrame.new(0, 0, part.Size.Z/2)
  112.     local edgeD = cf * CFrame.new(0, 0, -part.Size.Z/2)
  113.    
  114.     local edgeAx, edgeAz = project(edgeA.X, edgeA.Y, edgeA.Z)
  115.     local edgeBx, edgeBz = project(edgeB.X, edgeB.Y, edgeB.Z)
  116.     local edgeCx, edgeCz = project(edgeC.X, edgeC.Y, edgeC.Z)
  117.     local edgeDx, edgeDz = project(edgeD.X, edgeD.Y, edgeD.Z)
  118.    
  119.     local extentsX = max(edgeAx, edgeBx, edgeCx, edgeDx) - min(edgeAx, edgeBx, edgeCx, edgeDx)
  120.     local extentsZ = max(edgeAz, edgeBz, edgeCz, edgeDz) - min(edgeAz, edgeBz, edgeCz, edgeDz)
  121.    
  122.     return round(extentsX, currentPlane.grid), round(extentsZ, currentPlane.grid)
  123. end
  124.  
  125. local states = {
  126.     neutral = 1;
  127.     collision = 2;
  128.     loading = 3;
  129. }
  130.  
  131. module.states = states
  132.  
  133. local function setState(object, state, downward)
  134.     if (object.state and (object.state == state or (object.state > state and not downward))) then
  135.         return
  136.     end
  137.    
  138.     object.state = state
  139.    
  140.     if (state == 1) then
  141.         if (NORMAL_COLOR3) then
  142.             object.model.PrimaryPart.Color = NORMAL_COLOR3
  143.         end
  144.         if (NORMAL_TRANSPARENCY) then
  145.             object.model.PrimaryPart.Transparency = NORMAL_TRANSPARENCY
  146.         end
  147.     elseif (state == 2) then
  148.         if (COLLISION_COLOR3) then
  149.             object.model.PrimaryPart.Color = COLLISION_COLOR3
  150.         end
  151.         if (COLLISION_TRANSPARENCY) then
  152.             object.model.PrimaryPart.Transparency = COLLISION_TRANSPARENCY
  153.         end
  154.     elseif (state == 3) then
  155.         if (LOAD_COLOR3) then
  156.             object.model.PrimaryPart.Color = LOAD_COLOR3
  157.         end
  158.         if (LOAD_TRANSPARENCY) then
  159.             object.model.PrimaryPart.Transparency = LOAD_TRANSPARENCY
  160.         end
  161.     end
  162.    
  163.     currentPlane.stateEvent:Fire(object.model, state)
  164. end
  165.  
  166. --[[
  167.     status
  168.     model
  169.     px, pz, r
  170.     sx, sz
  171. --]]
  172.  
  173. local function floatEqual(a, b)
  174.     return (math.abs(a - b) < .01)
  175. end
  176.  
  177. local function floatGreater(a, b)
  178.     return (a - b) > .01
  179. end
  180.  
  181. local function floatLesser(a, b)
  182.     return (b - a) > .01
  183. end
  184.  
  185. local function obstacleCollision()
  186.     local px, pz = cx, cz
  187.    
  188.     local collision = false
  189.    
  190.     for _, model in pairs(currentPlane.obstacles:GetChildren()) do
  191.         if (model.PrimaryPart) then
  192.            
  193.             local extentsX1, extentsZ1 = calculateExtents(model.PrimaryPart)
  194.             local x1, z1 = project(model.PrimaryPart.Position.X, model.PrimaryPart.Position.Y, model.PrimaryPart.Position.Z)           
  195.                        
  196.             for i = 1, #currentObjects do
  197.                 local object = currentObjects[i]
  198.                
  199.                 if (not object.collision) then
  200.                     local r = (object.r + cr) % 4          
  201.                    
  202.                     local x0, z0 = translate(object.px, -object.pz, cr)
  203.                     x0 = x0 + px
  204.                     z0 = z0 + pz
  205.                    
  206.                     local extentsX0, extentsZ0             
  207.                                
  208.                     if (r == 1 or r == 3) then
  209.                         extentsX0, extentsZ0 = object.sz, object.sx
  210.                     else
  211.                         extentsX0, extentsZ0 = object.sx, object.sz
  212.                     end    
  213.                    
  214.                     if (floatLesser(x0 - extentsX0/2, x1 + extentsX1/2) and floatGreater(x0 + extentsX0/2, x1 - extentsX1/2) and floatLesser(z0 - extentsZ0/2, z1 + extentsZ1/2) and floatGreater(z0 + extentsZ0/2, z1 - extentsZ1/2)) then
  215.                         collision = true
  216.                         object.collision = true
  217.                         setState(object, states.collision)
  218.                     end
  219.                 end
  220.             end
  221.         end
  222.     end
  223.    
  224.     for i = 1, #currentObjects do
  225.         local object = currentObjects[i]
  226.        
  227.         if (not object.collision and object.state == states.collision) then
  228.             setState(object, states.neutral, true)
  229.         else
  230.             object.collision = nil
  231.         end
  232.     end
  233.    
  234.     return not collision
  235. end
  236.  
  237. local function inputCapture() -- converts user inputs to 3d position, built in mobile compatibility
  238.     local position
  239.    
  240.     if (touch) then
  241.         local camera = workspace.CurrentCamera
  242.         local range = TOUCH_RANGE * (camera.Focus.p - camera.CFrame.p).magnitude/5 
  243.        
  244.         position = camera.Focus.p + camera.CFrame.lookVector * (camera.CoordinateFrame.lookVector.Y/2 + .5) * range
  245.     else
  246.         local hit, p = workspace:FindPartOnRayWithWhitelist(Ray.new(mouse.UnitRay.Origin, mouse.UnitRay.Direction * 999), {currentPlane.base})
  247.        
  248.         if (hit) then
  249.             position = p
  250.         end
  251.     end
  252.    
  253.     return position, cr
  254. end
  255.  
  256. local resting = false
  257.  
  258. local function calc(position, rotation, force)
  259.     if (not currentPlane or currentPlane.loading) then
  260.         return
  261.     end
  262.    
  263.     force = force == true
  264.    
  265.     local ux, uz
  266.    
  267.     if (position) then
  268.         ux, uz = project(position.X, position.Y, position.Z)
  269.     else
  270.         ux, uz = ax or 0, az or 0
  271.     end
  272.          
  273.     local nr = rotation or cr
  274.        
  275.     local nx = round(ux, currentPlane.grid)
  276.     local nz = round(uz, currentPlane.grid)
  277.    
  278.     local extentsX, extentsZ = translate(currentExtentsX, currentExtentsZ, nr)
  279.     extentsX = abs(extentsX)
  280.     extentsZ = abs(extentsZ)
  281.    
  282.     if (floatEqual(extentsX/2 % currentPlane.grid, 0)) then
  283.         nx = nx + currentPlane.grid/2
  284.     end
  285.    
  286.     if (floatEqual(extentsZ/2 % currentPlane.grid, 0)) then
  287.         nz = nz + currentPlane.grid/2
  288.     end
  289.    
  290.     nx = nx + currentPlane.offsetX
  291.     nz = nz + currentPlane.offsetZ
  292.    
  293.     local borderX = currentPlane.size.X/2
  294.     local borderZ = currentPlane.size.Z/2
  295.    
  296.     ax = ux
  297.     az = uz
  298.    
  299.     if (nx + extentsX/2 > borderX) then
  300.         nx = nx - (nx + extentsX/2 - borderX)
  301.     elseif (nx - extentsX/2 < -borderX) then
  302.         nx = nx - (nx - extentsX/2 + borderX)
  303.     end
  304.    
  305.     if (nz + extentsZ/2 > borderZ) then
  306.         nz = nz - (nz + extentsZ/2 - borderZ)
  307.     elseif (nz - extentsZ/2 < -borderZ) then
  308.         nz = nz - (nz - extentsZ/2 + borderZ)
  309.     end
  310.    
  311.     if (force or nx ~= cx or nz ~= cz or cr ~= nr) then
  312.         cx, cz, cr = nx, nz, nr
  313.         resting = false
  314.         currentPosition = (Vector3.new(ox, oy, oz) + currentXAxis * nx + currentZAxis * nz)
  315.         obstacleCollision()
  316.     end
  317. end
  318.  
  319. local function render()
  320.     if (resting) then
  321.         return
  322.     end
  323.    
  324.     if (INTERPOLATION) then
  325.         local delta = 1/60
  326.        
  327.         springVelocity = (springVelocity + (currentPosition - springPosition)) * INTERPOLATION_DAMP * 60 * delta
  328.         springPosition = springPosition + springVelocity
  329.        
  330.         local extentsX, extentsZ = translate(currentExtentsX, currentExtentsZ, cr)
  331.        
  332.         local vx, vz = 9 * springVelocity:Dot(currentXAxis)/abs(extentsX), 9 * springVelocity:Dot(currentZAxis)/abs(extentsZ)
  333.         local r
  334.        
  335.         if (not floatEqual(tweenGoalRotation, cr * math.pi/2)) then
  336.             tweenStartRotation = tweenCurrentRotation
  337.             tweenGoalRotation = cr * math.pi/2
  338.             tweenAlpha = 0
  339.         end
  340.                
  341.         if (tweenAlpha < 1) then
  342.             tweenAlpha = min(1, tweenAlpha + delta/ROTATION_SPEED)
  343.             tweenCurrentRotation = angleLerp(tweenStartRotation, tweenGoalRotation, 1 - (1 - tweenAlpha)^2)
  344.             r = tweenCurrentRotation
  345.         else
  346.             r = cr * math.pi/2
  347.         end
  348.        
  349.        
  350.         local effectAngle = CFrame.Angles(math.sqrt(math.abs(vz/100)) * math.sign(vz), 0, math.sqrt(math.abs(vx/100)) * math.sign(vx))
  351.        
  352.         local rotationCFrame = currentAxis * effectAngle * CFrame.Angles(0, r, 0)
  353.         local centerCFrame = rotationCFrame + springPosition
  354.        
  355.         for i = 1, #currentObjects do
  356.             local object = currentObjects[i]
  357.                        
  358.             local x, z = object.px, object.pz          
  359.            
  360.             object.model:SetPrimaryPartCFrame(centerCFrame * CFrame.Angles(0, object.r * math.pi/2, 0) + rotationCFrame * Vector3.new(x, object.sy/2, z))
  361.         end    
  362.        
  363.         if (springVelocity.magnitude < .01 and tweenAlpha >= 1) then
  364.             resting = true
  365.         end
  366.     else
  367.         local rotationCFrame = currentAxis * CFrame.Angles(0, cr * math.pi/2, 0)       
  368.        
  369.         for i = 1, #currentObjects do
  370.             local object = currentObjects[i]
  371.             local x, z = object.px, object.pz
  372.            
  373.             object.model:SetPrimaryPartCFrame(rotationCFrame * CFrame.Angles(0, object.r * math.pi/2, 0) + rotationCFrame * Vector3.new(x, object.sy/2, z) + currentPosition)
  374.         end
  375.        
  376.         resting = true
  377.     end
  378. end
  379.  
  380. local function run(display)
  381.     local position, rotation = inputCapture()
  382.    
  383.     if (position or rotation) then
  384.         calc(position, rotation)
  385.         if (display) then
  386.             render()
  387.         end
  388.     end
  389. end
  390.  
  391. local function place()
  392.     if (currentPlane and (obstacleCollision()) and (tick() - lastPlacement) >= PLACEMENT_COOLDOWN and not currentPlane.loading) then
  393.         lastPlacement = tick()
  394.                
  395.         local modelCFrames = {}
  396.        
  397.         for i = 1, #currentObjects do
  398.             local object = currentObjects[i]
  399.             modelCFrames[i] = currentAxis * CFrame.Angles(0, (object.r + cr) * math.pi/2, 0) +  (currentAxis * CFrame.Angles(0, cr * math.pi/2, 0)) * Vector3.new(object.px, object.sy/2, object.pz) + currentPosition
  400.         end
  401.        
  402.         currentEvent:Fire(modelCFrames)    
  403.     end
  404. end
  405.  
  406. local function rotate()
  407.     calc(nil, (cr + 1) % 4)
  408.     render()
  409. end
  410.  
  411. local function inputRotate(_, userInputState, inputObject)
  412.     if (currentPlane and userInputState == Enum.UserInputState.End) then
  413.         rotate()
  414.     end
  415. end
  416.  
  417. local function inputPlace(_, userInputState, inputObject)
  418.     if (currentPlane and userInputState == Enum.UserInputState.End) then
  419.         place()
  420.     end
  421. end
  422.  
  423. local function bindInputs()
  424.     if (not OVERRIDE_CONTROLS) then
  425.         game:GetService("ContextActionService"):BindActionAtPriority("PlacementModule_Rotate", inputRotate, false, INPUT_PRIORITY, Enum.KeyCode.R)
  426.         game:GetService("ContextActionService"):BindActionAtPriority("PlacementModule_Place", inputPlace, false, INPUT_PRIORITY, Enum.UserInputType.MouseButton1)
  427.     end
  428. end
  429.  
  430. local function unbindInputs()
  431.     if (not OVERRIDE_CONTROLS) then
  432.         game:GetService("ContextActionService"):UnbindAction("PlacementModule_Rotate")
  433.         game:GetService("ContextActionService"):UnbindAction("PlacementModule_Place")
  434.     end
  435. end
  436.  
  437. local function enablePlacement(plane, models, prealigned)
  438.     if (plane == currentPlane) then
  439.         return
  440.     elseif (currentPlane) then
  441.         currentPlane:disable()
  442.     end
  443.    
  444.     if (type(models) ~= "table") then
  445.         models = {models}
  446.     end
  447.    
  448.     lastRenderCycle = tick()
  449.    
  450.     currentPlane = plane
  451.     currentBase = plane.base
  452.  
  453.     local planePosition = currentBase.CFrame * Vector3.new(0, currentBase.Size.Y/2, 0) 
  454.    
  455.     resting = false
  456.     ox, oy, oz = planePosition.X, planePosition.Y, planePosition.Z
  457.     currentXAxis = currentBase.CFrame.rightVector
  458.     currentYAxis = currentBase.CFrame.upVector
  459.     currentZAxis = currentBase.CFrame.lookVector
  460.     currentAxis = CFrame.new(0, 0, 0, currentXAxis.X, currentYAxis.X, -currentZAxis.X, currentXAxis.Y, currentYAxis.Y, -currentZAxis.Y, currentXAxis.Z, currentYAxis.Z, -currentZAxis.Z)
  461.     currentObjects = {}
  462.     dxx, dxy, dxz = currentXAxis.X, currentXAxis.Y, currentXAxis.Z
  463.     dzx, dzy, dzz = currentZAxis.X, currentZAxis.Y, currentZAxis.Z
  464.     cx, cy, cz, cr = 0, 0, 0, 0
  465.    
  466.     springVelocity = Vector3.new(0, 0, 0)
  467.     springPosition = Vector3.new(0, 0, 0)
  468.    
  469.     tweenAlpha = 0
  470.     tweenCurrentRotation = 0
  471.     tweenGoalRotation = 0
  472.     tweenStartRotation = 0
  473.    
  474.     local position, _ = inputCapture()
  475.    
  476.     if (not position) then
  477.         position = planePosition
  478.     end
  479.    
  480.     springPosition = position
  481.    
  482.     do
  483.         local extentsXMin, extentsXMax = 10e10, -10e10
  484.         local extentsZMin, extentsZMax = 10e10, -10e10
  485.        
  486.         for i = 1, #models do
  487.             local model = models[i]
  488.             local object = {}
  489.             object.model = model
  490.            
  491.             local lookVector = object.model.PrimaryPart.CFrame.lookVector  
  492.             local theta
  493.             local px, pz
  494.            
  495.             if (prealigned) then
  496.                 local position = object.model.PrimaryPart.CFrame * Vector3.new(0, -object.model.PrimaryPart.Size.Y/2 , 0)      
  497.                 px, pz = project(position.X, position.Y, position.Z)
  498.  
  499.                 theta = math.acos(math.clamp(lookVector:Dot(currentZAxis), -1, 1))
  500.                 local cross = lookVector:Cross(currentZAxis)
  501.                
  502.                 if (cross:Dot(currentYAxis) > 0) then
  503.                     theta = -theta
  504.                 end
  505.                
  506.             else
  507.                 px, pz = object.model.PrimaryPart.Position.X, object.model.PrimaryPart.Position.Z
  508.                 theta = math.atan2(lookVector.X, lookVector.Z)     
  509.             end
  510.            
  511.             local x, z = model.PrimaryPart.Size.X, model.PrimaryPart.Size.Z
  512.            
  513.             object.r = round((theta % (2 * math.pi))/(math.pi/2), 1)
  514.            
  515.             if (object.r == 1 or object.r == 3) then
  516.                 x, z = z, x
  517.             end
  518.            
  519.             local x1, x2 = px + x/2, px - x/2
  520.             local z1, z2 = pz + z/2, pz - z/2  
  521.            
  522.             if (x2 < extentsXMin) then
  523.                 extentsXMin = x2
  524.             end
  525.             if (x1 > extentsXMax) then
  526.                 extentsXMax = x1
  527.             end
  528.            
  529.             if (z2 < extentsZMin) then
  530.                 extentsZMin = z2
  531.             end
  532.             if (z1 > extentsZMax) then
  533.                 extentsZMax = z1
  534.             end
  535.                        
  536.            
  537.             model.PrimaryPart.Transparency = .5
  538.             model.PrimaryPart.Anchored = true
  539.             model.PrimaryPart.CanCollide = false
  540.            
  541.             setState(object, plane.loading and states.loading or states.neutral)
  542.            
  543.             currentObjects[i] = object
  544.         end
  545.        
  546.         currentExtentsX, currentExtentsZ = round(extentsXMax - extentsXMin, currentPlane.grid), round(extentsZMax - extentsZMin, currentPlane.grid)
  547.                
  548.         for i = 1, #currentObjects do
  549.             local object = currentObjects[i]
  550.             local px, pz
  551.            
  552.             if (prealigned) then
  553.                 local position = object.model.PrimaryPart.CFrame * Vector3.new(0, -object.model.PrimaryPart.Size.Y/2, 0)       
  554.                 px, pz = project(position.X, position.Y, position.Z)
  555.             else
  556.                 px, pz = object.model.PrimaryPart.Position.X, object.model.PrimaryPart.Position.Z
  557.             end
  558.            
  559.             object.px = px - (extentsXMin + extentsXMax)/2
  560.             object.pz = (pz - (extentsZMin + extentsZMax)/2) * (prealigned and -1 or 1)
  561.                                    
  562.             object.sx, object.sy, object.sz = object.model.PrimaryPart.Size.X, object.model.PrimaryPart.Size.Y, object.model.PrimaryPart.Size.Z
  563.         end
  564.     end
  565.    
  566.     renderConnection = runService.RenderStepped:connect(run)
  567.     module.currentPlane = currentPlane
  568.     currentEvent = Instance.new("BindableEvent")
  569.    
  570.     if (GRID_TEXTURE) then
  571.         currentTexture = Instance.new("Texture", currentPlane.base)
  572.         currentTexture.Texture = GRID_TEXTURE
  573.         currentTexture.Face = Enum.NormalId.Top
  574.         currentTexture.StudsPerTileU = currentPlane.grid
  575.         currentTexture.StudsPerTileV = currentPlane.grid
  576.     end
  577.        
  578.     bindInputs()
  579.    
  580.     run(true)
  581.        
  582.     return currentEvent.Event
  583. end
  584.  
  585. local function disablePlacement(plane)
  586.     if (currentPlane) then
  587.         renderConnection:disconnect()
  588.         renderConnection = nil
  589.         currentPlane = nil
  590.         module.currentPlane = nil
  591.         currentEvent:Destroy()
  592.         currentEvent = nil 
  593.        
  594.         if (currentTexture) then
  595.             currentTexture:Destroy()
  596.             currentTexture = nil
  597.         end
  598.        
  599.         for i = 1, #currentObjects do
  600.             local object = currentObjects[i]
  601.             object.model = nil
  602.             currentObjects[i] = nil
  603.         end
  604.        
  605.         unbindInputs()
  606.     end
  607. end
  608.  
  609. local function setLoading(plane, isLoading)
  610.     if (plane.loading == isLoading) then
  611.         return
  612.     end
  613.    
  614.     plane.loading = isLoading
  615.    
  616.     if (plane == currentPlane) then
  617.         if (isLoading) then
  618.             for i = 1, #currentObjects do
  619.                 setState(currentObjects[i], states.loading)
  620.             end
  621.         else
  622.             for i = 1, #currentObjects do
  623.                 setState(currentObjects[i], states.neutral, true)
  624.             end
  625.            
  626.             obstacleCollision()
  627.         end
  628.     end
  629. end
  630.  
  631. module.new = function(base, obstacles, grid)
  632.     local plane = {}
  633.     plane.base = base
  634.     plane.obstacles = obstacles
  635.     plane.position = base.Position
  636.     plane.size = base.Size
  637.    
  638.     if (math.floor(.5 + plane.size.X/grid) % 2 == 0) then
  639.         plane.offsetX = -grid/2
  640.     else
  641.         plane.offsetX = 0
  642.     end
  643.    
  644.     if (math.floor(.5 + plane.size.Z/grid) % 2 == 0) then
  645.         plane.offsetZ = -grid/2
  646.     else
  647.         plane.offsetZ = 0
  648.     end
  649.    
  650.    
  651.     plane.stateEvent = Instance.new("BindableEvent")
  652.     plane.stateChanged = plane.stateEvent.Event
  653.    
  654.     plane.grid = grid
  655.     plane.enable = enablePlacement
  656.     plane.disable = disablePlacement
  657.     plane.rotate = rotate
  658.     plane.place = place
  659.     plane.setLoading = setLoading
  660.    
  661.     return plane
  662. end
  663.  
  664. module.setLoading = setLoading
  665. module.currentPlane = false
  666.  
  667. return module
  668. ~~~~~~~~~~~~~~~~~
Advertisement
Add Comment
Please, Sign In to add comment