Advertisement
Cat_in_the_hat

Cirle radius in parts

Dec 2nd, 2024
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.28 KB | None | 0 0
  1. local luckyBoxPick = BlockService.getAllBlocks({ItemType.CLAY_WHITE})
  2.  
  3. if #luckyBoxPick > 0 then
  4.     local block = luckyBoxPick[math.random(1, #luckyBoxPick)]
  5.     local centerPosition = block.position + Vector3.new(0, 1.6, 0)
  6.     local circleRadius = 13 -- Example radius
  7.     local partCount = 8 + (circleRadius * 2)  
  8.     local partSize = Vector3.new(1, 0.2, 0.3)
  9.     local spaceGap = 0.5
  10.  
  11.     for i = 1, partCount do
  12.         local angle = (i / partCount) * math.pi * 2
  13.         local offsetX = math.cos(angle) * (circleRadius + partSize.X / 2 + spaceGap)
  14.         local offsetZ = math.sin(angle) * (circleRadius + partSize.X / 2 + spaceGap)
  15.         local partPosition = centerPosition + Vector3.new(offsetX, 0, offsetZ)
  16.  
  17.         local part = PartService.createPart(ItemType.WOOL_WHITE, partPosition)
  18.         part:setSize(partSize)
  19.         part:setAnchored(true)
  20.         part:setCollidable(false)
  21.  
  22.         local lookAtCFrame = CFrame.new(partPosition, centerPosition)
  23.         part:setCFrame(lookAtCFrame)
  24.     end
  25.  
  26.     local nearbyEntities = EntityService.getNearbyEntities(centerPosition, 10)
  27.     if #nearbyEntities > 0 then
  28.         local entity = nearbyEntities[1]
  29.  
  30.         local function updatePartsOrientation()
  31.             task.spawn(function()
  32.                 while entity:isAlive() do
  33.                     local entityPos = entity:getPosition()
  34.                     for i = 1, partCount do
  35.                         local angle = (i / partCount) * math.pi * 2
  36.                         local offsetX = math.cos(angle) * (circleRadius + partSize.X / 2 + spaceGap)
  37.                         local offsetZ = math.sin(angle) * (circleRadius + partSize.X / 2 + spaceGap)
  38.                         local partPosition = centerPosition + Vector3.new(offsetX, 0, offsetZ)
  39.                         local part = PartService.getPartAt(partPosition)
  40.  
  41.                         if part then
  42.                             local direction = (entityPos - partPosition).unit
  43.                             local lookAtCFrame = CFrame.new(partPosition, partPosition + direction)
  44.                             part:setCFrame(lookAtCFrame)
  45.                         end
  46.                     end
  47.                     task.wait(0)
  48.                 end
  49.             end)
  50.         end
  51.  
  52.         updatePartsOrientation()
  53.     end
  54. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement