Hello! I am working on a pet system for my game right now and one thing I can’t figure out how to have more than one pets following a player without those pets overlapping eachother, I want these pets circled around a player.
I have tried to look up solutions here but I cannot find any.
Could anyone help? It would be so much appreciated
local runService = game:GetService("RunService")
local character = script.Parent
local rootPart = character.HumanoidRootPart
local distance = 10
local amount = 5
local parts = {}
for i = 1, amount do
parts[i] = Instance.new("Part")
parts[i].Anchored = true
parts[i].Size = Vector3.new(2, 2, 2)
parts[i].Parent = workspace
end
runService.Heartbeat:Connect(function(deltaTime)
for i = 1, amount do
local angle = i / amount * math.pi * 2
local offset = Vector3.new(math.sin(angle), 0, math.cos(angle)) * distance
parts[i].Position = rootPart.Position + offset
end
end)
and this video might help you understand the angle = i / amount * math.pi * 2 part
i will hopefully have a video in the future talking about sin and cos
Thanks for this, I can’t wrap myself around this confusing code so what I decided to do is add a vector3 value on X and Z for each number of pets, so like Vector3.new(5 + 2 * pets, 0, 5 + 2 * pets)