Hello, I am trying to make pet system but;
I want to make the movement smoother, and that the pet stays on the back and doesn’t gets far, using pathways.
Code:
while (true) do
wait()
if (not Pet) then
break
end
coroutine.wrap(function()
local npcpos = Pet.Torso.Position
local charpos = Player.Character.HumanoidRootPart.Position
if (Player.Character.HumanoidRootPart.Position - Pet.Torso.Position).Magnitude < 6 then
return
elseif ((Player.Character.HumanoidRootPart.Position - Pet.Torso.Position).Magnitude > 23) then
print("too far..")
Pet:MoveTo(Player.Character.HumanoidRootPart.Position - Vector3.new(0,0,2))
end
npcpath:ComputeAsync(Pet.Torso.Position, Player.Character.HumanoidRootPart.Position - Vector3.new(0,0,2))
local target
if npcpath.Status == Enum.PathStatus.Success then
local waypoints = npcpath:GetWaypoints()
target = waypoints[2].Position
else
target = charpos
end
Pet.Humanoid:MoveTo(target)
end)()
end