Floating Pet System, i'm not satisfied with the code

I have a floating pet system, i got it from a tutorial, and edited it a bit to improve it, and optimize it more, here is the script:

if Player then
	local Char = Player.Character
	if Char then
		local HRP = Char.HumanoidRootPart
		local CPet = Pet:Clone()
		CPet.Parent = Char
		
		local BPos = Instance.new("BodyPosition")
		BPos.Parent = CPet
		BPos.D = 1500
		BPos.P = 10000
		BPos.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
		
		local BGyro = Instance.new("BodyGyro")
		BGyro.Parent = CPet
		BGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
		
		CPet.CanCollide = false
		CPet.Massless = true
		while true do
			wait(0.3)
			local MoveToPos = (HRP.CFrame * CFrame.new(-2, -1, 0)).p
			BPos.Position = MoveToPos
			BGyro.CFrame = HRP.CFrame
		end
	end
end

Well, i want to know if there’s a way to improve it more, because i don’t feel satisfied with the whole code, i think there’s a better way to do this or improve it, thanks for reading.

1 Like

You could scrap all of this code by using a align position constraint with an attachment over the players shoulder. It would act the same.

1 Like

Yes, i tried to use AlignPosition, however, i want to keep a smooth transition, correct me if i’m wrong, but it only replicated the character’s movement with a delay. I don’t know if i’ve used it in a wrong way.

You would just need to amp up the properties just like you did the gyro.

1 Like