Pets Form Into a Circle Around The Player Not Working Properly!

:wave: Hello Welcome to my post!

  1. What do you want to achieve? Having The Pet Around The Player But Circular

  2. What is the issue? Circularity is broken as the character moves. Video: https://gyazo.com/8122f625baba9357e85d968e522f5b7c

  3. What solutions have you tried so far? I haven’t actually tried anything because I’ve never seen anyone do this with lerp before.

Code:

local LERP_ALPHA = 0.08;

game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(chr)
		local character = chr
		local hrp = character:WaitForChild("HumanoidRootPart")

		local parts = {}
		local numberOfParts = 4

		for _ = 1, numberOfParts do
			table.insert(parts, game.ReplicatedStorage.Part:Clone())
		end

		for i, part in pairs(parts) do
			part.Anchored = true
			part.CanCollide = false
			part.Parent = workspace
		end

		local fullCircle = 2 * math.pi
		local radius = 10

		local function getXAndZPositions(angle)
			local x = math.cos(angle) * radius
			local z = math.sin(angle) * radius
			return x, z
		end

		game:GetService("RunService").Heartbeat:Connect(function(step)
			for i, part in pairs(parts) do
				local petCframe = part.CFrame
				local characterCframe = hrp.CFrame
				
				
				local angle = i * (fullCircle / #parts)
				local x, z = getXAndZPositions(angle)
				
				local position = (hrp.CFrame * CFrame.new(x, 0, z))
				
				local newCframe = petCframe:Lerp(position, LERP_ALPHA)
				part.CFrame = newCframe
			end
		end)
		
	end)
end)
1 Like

Doesn’t Lerp interpolate a point between your position and the pet position? If you wanted the pet rotation to remain fixed around you at a certain radius, why not fix that radius? why use Lerp?

I might be confused on your objective.

not exactly like that i want it to follow the character as smooth

if you change

local position = (hrp.CFrame * CFrame.new(x, 0, z))

to

local position = CFrame.new(x, 0, z) + hrp.Position

then it wont do that

Instead of lerping, use BodyPostion to make pets follow players.

body positions don’t always give the same position

bro its a cframe + position bad idea not worked…

strange that worked in my head what happened when you tried it

not worked… -.-.-.-.–.-…-.–.-.-.-.

did the pets go close to the character or where they far away

IM USED ALIGN POSITION AND WORKED

local character = chr
		local hrp = character:WaitForChild("HumanoidRootPart")
		
		

		
		
		local newPet = game.ReplicatedStorage.Model:Clone()
		newPet.Parent = game.Workspace


		newPet:SetPrimaryPartCFrame(hrp.CFrame)
		
		local angle = 1 * 2 * math.pi / 1
		
		local ac = Instance.new("Attachment",hrp)
		ac.Visible = false
		ac.Name = "ACharacter"
		ac.Position = Vector3.new(math.sin(angle) * 10, 0, math.cos(angle) * 10)     

		local ap = Instance.new("Attachment",newPet.PrimaryPart)
		ap.Visible = false
		ap.Name = "APet"



		local alignPosition = Instance.new("AlignPosition")
		alignPosition.MaxForce = 25000
		alignPosition.Attachment0 = ap
		alignPosition.Attachment1 = ac
		alignPosition.Responsiveness = 25
		alignPosition.Parent = newPet

		local alignOrientation = Instance.new("AlignOrientation")
		alignOrientation.MaxTorque = 25000
		alignOrientation.Attachment0 = ap
		alignOrientation.Attachment1 = ac
		alignOrientation.Responsiveness = 25
		alignOrientation.Parent = newPet
1 Like

I knew the Lerp was not the way to go… glad the align worked out for you.

Also, do you mind if you show us the finished result in video, i am curious to see how it looks.

i only maked 1 part i making inventory system sorry

1 Like