Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local runService = game:GetService("RunService")
- local playersFolder = workspace:WaitForChild("Players")
- local petsPerRow = 5
- local offsetX = 4
- local offsetZ = 5
- local offsetPlayer = 6
- local function positionPets(character, playerFolder, deltaTime, sin, cos)
- local petCount = #playerFolder:GetChildren()
- local rows = math.ceil(petCount / petsPerRow)
- for i, pet in pairs(playerFolder:GetChildren()) do
- local row = math.floor( (i - 1) / petsPerRow)
- local col = (i - 1) % petsPerRow
- local characterSize = character:GetExtentsSize()
- local petSize = pet:GetExtentsSize()
- local petsInRow = math.min(petCount - row * petsPerRow, petsPerRow)
- local x = (col - petsInRow/2 + 0.5) * offsetX
- local y = petSize.Y/2 - characterSize.Y/2
- local z = (row * offsetZ) + offsetPlayer
- if pet:FindFirstChild("Attack").Value ~= nil then
- -- animacja ataku - bo mamy coś do zaatakowania
- local position = (pet:FindFirstChild("Attack").Value.CFrame * CFrame.new(x, 0, z) ).p
- local lookAt = pet:FindFirstChild("Attack").Value.Position
- if pet:FindFirstChild("Walks") then
- -- animacja ataku chodzących petów
- pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(CFrame.new(position, lookAt) *
- CFrame.new(0, 1 + sin, 0) * CFrame.fromEulerAnglesXYZ(0,0,cos),0.1 ))
- else
- -- animacja ataku petów latających
- pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(CFrame.new(position, lookAt) *
- CFrame.new(0, 3+math.sin(time()*7)/2, 0) * CFrame.fromEulerAnglesXYZ(cos,0,0),0.1 ))
- end
- else
- -- animacja poruszania lub stania - bo nie ma nic do ataku
- if character.Humanoid.MoveDirection.Magnitude > 0 then
- if pet:FindFirstChild("Walks") then
- pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(
- character.PrimaryPart.CFrame * CFrame.new(x, y + sin, z) * CFrame.fromEulerAnglesXYZ(0,0,cos),0.1))
- elseif pet:FindFirstChild("Flying") then
- pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(
- character.PrimaryPart.CFrame * CFrame.new(x, y / 2 +math.sin(time()*3)+1, z), 0.1))
- end
- else
- if pet:FindFirstChild("Walks") then
- pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(
- character.PrimaryPart.CFrame * CFrame.new(x, y, z) ,0.1))
- elseif pet:FindFirstChild("Flying") then
- pet:SetPrimaryPartCFrame(pet.PrimaryPart.CFrame:Lerp(
- character.PrimaryPart.CFrame * CFrame.new(x, y / 2 + math.sin(time()*3)+1, z) , 0.1))
- end
- end
- end
- end
- end
- runService.RenderStepped:Connect(function(deltaTime)
- local sin = (math.sin(15 * time() + 1.6)/.5)+1
- local cos = math.cos(7 * time() + 1) / 4
- for i, playerFolder in pairs(playersFolder:GetChildren()) do
- local player = game.Players:FindFirstChild(playerFolder.Name)
- if player ~= nil then
- local character = player.Character or nil
- if character ~= nil then
- positionPets(character, playerFolder, deltaTime, sin, cos)
- end
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement