drakon-firestone

Untitled

Jun 7th, 2023
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. local runService = game:GetService("RunService")
  2.  
  3. local playersFolder = workspace:WaitForChild("Players")
  4.  
  5. local petsPerRow = 5
  6.  
  7. local offsetX = 4
  8. local offsetZ = 5
  9. local offsetPlayer = 6
  10.  
  11. local function positionPets(character, playerFolder, deltaTime, sin, cos)
  12. local petCount = #playerFolder:GetChildren()
  13. local rows = math.ceil(petCount / petsPerRow)
  14.  
  15. for i, pet in pairs(playerFolder:GetChildren()) do
  16. local row = math.floor( (i - 1) / petsPerRow)
  17. local col = (i - 1) % petsPerRow
  18.  
  19. local characterSize = character:GetExtentsSize()
  20. local petSize = pet:GetExtentsSize()
  21. local petsInRow = math.min(petCount - row * petsPerRow, petsPerRow)
  22.  
  23. local x = (col - petsInRow/2 + 0.5) * offsetX
  24. local y = petSize.Y/2 - characterSize.Y/2
  25. local z = (row * offsetZ) + offsetPlayer
  26.  
  27.  
  28. if pet:FindFirstChild("Attack").Value ~= nil then
  29. -- animacja ataku - bo mamy coś do zaatakowania
  30. local position = (pet:FindFirstChild("Attack").Value.CFrame * CFrame.new(x, 0, z) ).p
  31. local lookAt = pet:FindFirstChild("Attack").Value.Position
  32.  
  33. if pet:FindFirstChild("Walks") then
  34. -- animacja ataku chodzących petów
  35. pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(CFrame.new(position, lookAt) *
  36. CFrame.new(0, 1 + sin, 0) * CFrame.fromEulerAnglesXYZ(0,0,cos),0.1 ))
  37. else
  38. -- animacja ataku petów latających
  39. pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(CFrame.new(position, lookAt) *
  40. CFrame.new(0, 3+math.sin(time()*7)/2, 0) * CFrame.fromEulerAnglesXYZ(cos,0,0),0.1 ))
  41. end
  42.  
  43.  
  44. else
  45. -- animacja poruszania lub stania - bo nie ma nic do ataku
  46. if character.Humanoid.MoveDirection.Magnitude > 0 then
  47. if pet:FindFirstChild("Walks") then
  48. pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(
  49. character.PrimaryPart.CFrame * CFrame.new(x, y + sin, z) * CFrame.fromEulerAnglesXYZ(0,0,cos),0.1))
  50. elseif pet:FindFirstChild("Flying") then
  51. pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(
  52. character.PrimaryPart.CFrame * CFrame.new(x, y / 2 +math.sin(time()*3)+1, z), 0.1))
  53. end
  54. else
  55. if pet:FindFirstChild("Walks") then
  56. pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(
  57. character.PrimaryPart.CFrame * CFrame.new(x, y, z) ,0.1))
  58. elseif pet:FindFirstChild("Flying") then
  59. pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(
  60. character.PrimaryPart.CFrame * CFrame.new(x, y / 2 + math.sin(time()*3)+1, z) , 0.1))
  61. end
  62. end
  63. end
  64.  
  65.  
  66.  
  67.  
  68. end
  69. end
  70.  
  71. runService.RenderStepped:Connect(function(deltaTime)
  72. local sin = (math.sin(15 * time() + 1.6)/.5)+1
  73. local cos = math.cos(7 * time() + 1) / 4
  74.  
  75. for i, playerFolder in pairs(playersFolder:GetChildren()) do
  76. local player = game.Players:FindFirstChild(playerFolder.Name)
  77. if player ~= nil then
  78. local character = player.Character or nil
  79. if character ~= nil then
  80. positionPets(character, playerFolder, deltaTime, sin, cos)
  81. end
  82. end
  83. end
  84.  
  85. end)
Add Comment
Please, Sign In to add comment