Hi, I’m looking for a way to create a pet system similar to the one shown below?
I want the Pet to follow at a constant distance regardless of Players position aswell as stopping once within a certain magnitude.
I’ve tried using simple Move to() but had no such success and all of the tutorials I’ve seen just show the Pet as being static either beside or behind the Player - I’m not looking to have that effect.
Thank you
EDIT
I’ve made progress - However, as you can see the Pet has a sort of jittering effect when moving?
I’m unsure how best to combat this?
Server:GetService('RunService').RenderStepped:Connect(function(dt, ...)
for __,Folder in (PlayerList:GetChildren(...)) do
for __,PetFolder in (Folder:GetChildren(...)) do
if PetFolder:IsA('Folder') and PetFolder.Name == 'Pet' then
local Pet = PetFolder:FindFirstChild('Pet')
local Character = PetFolder.Parent:FindFirstChildOfClass('Model')
repeat task.wait(...) until Character
local HumanoidRootPart = Character:WaitForChild('HumanoidRootPart', 5)
local Humanoid = Character:WaitForChild('Humanoid', 5)
if Pet and Character and HumanoidRootPart and Humanoid then
if Humanoid.Health > 0 then
local Magnitude = (HumanoidRootPart.Position - Pet.PrimaryPart.Position).Magnitude
local RaycastParam = RaycastParams.new()
RaycastParam.FilterType = Enum.RaycastFilterType.Exclude
RaycastParam.FilterDescendantsInstances = {PlayerList}
local X, Y, Z = HumanoidRootPart.Position.X, 0, HumanoidRootPart.Position.Z
local Result = Server:GetService('Workspace'):Blockcast(Pet.PrimaryPart.CFrame + Vector3.new(0, 5, 0), Pet.PrimaryPart.Size, Vector3.new(0, -500, 0), RaycastParam)
if Result then
Y = Result.Position.Y + Pet.PrimaryPart.Size.Y / 2
end
local Dir = (Pet.PrimaryPart.Position - HumanoidRootPart.Position)
local CF = (Pet.PrimaryPart.CFrame - Pet.PrimaryPart.Position) + HumanoidRootPart.Position + Dir.Unit * math.min(Dir.Magnitude, 5)
CF = CFrame.lookAt(Vector3.new(CF.X, Y, CF.Z), Vector3.new(X, Y, Z))
Pet.PrimaryPart.CFrame = Pet.PrimaryPart.CFrame:Lerp(CF, 0.1)
end
end
end
end
end
end)