Vector Offset not correctly working on Pet Positioning System! [HELP NEEDED]

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

How about using a Cframe value instead of a vector3value for the offset as cframe is both position and orientation

1 Like

Thanks for your response!

But i don’t want to offset my rotation, only my position. Using orientation would just rotate the model and not rotate it around the player.

If i am wrong, please reply to me.

Have a great day!

Yeah but it not rotating with the offset is due to the cframe.Angles

1 Like

i think you can do

CFrame.Angles(0, math.rad(Torso.Orientation.Y), 0):ToWorldSpace(CFrame.new(vectorOffset))

--also try toobjectspace or swapping order or changing angles if it doesnt work

or you could iterate through the pets and then position them at

local x = math.cos(rotation) * distance
local z = math.sin(rotation) * distance

where

local rotation = math.rad(Torso.Orientation.Y)

and then offset the y by

local y = Torso.Position.Y + pet:GetExtentsOffset()/2
1 Like

Ok, so how would I change it then?

Ok, that seams great, i will try it out tomorrow.

Thanks!

And i think you can use:
CFrame:ToObjectSpace()
And:
CFrame:ToWorldSpace()