Hello DevForum!,
I am currently working on a pet system and I found a piece of code that does the calculations for the positioning of the pets.
The code works great, but I have a very big pet. I would need a Y offset and a Z offset so it doesn’t keep crashing against the ground or against my character. I added a vector3 value to each pet and just tried adding my vectorOffset.
For the biggest part that works fine, but if the player rotates, the vector offset won’t rotate with it. I have no idea how I could implement this into my code and this is why I am asking for your help.
Video (Note: the grey dot is the position where the pet should be aligned):
Piece of the code:
runService.RenderStepped:Connect(function(deltaTime)
for _, folder in pairs(activePets:GetChildren()) do
local player = game.Players:GetPlayerByUserId(folder.Name)
local playerName = player.Name
local character = player.Character
if not character then return end
--local Deg = (math.pi*2)/#CurrentPets
local SubI = 1
for i,v in pairs(folder:GetChildren()) do
local vectorOffset = v:FindFirstChildOfClass("Vector3Value")
if SubI > 3 then
SubI = 1
end
local Row = math.ceil(i/3)
local startingCFrame = character.PrimaryPart.CFrame
local CF = startingCFrame * CFrame.new(-6 + (4*SubI),0,(4*Row)+3) * CFrame.Angles(0,math.rad(90),0) + vectorOffset.Value
v.PrimaryPart.CFrame = CF
SubI += 1
end
end
end)
Any help is as always greatly appreciated and I hope you have a nice day/ evening!
Thanks for reading