Pet Follower Issue

Hello I have been working on a pet humanoid follower and I have some issue the pet doesn’t go behind the player


Here is the code :

RunService.RenderStepped:Connect(function(deltaTime)
    for _ , folder in PlayerPets:GetChildren() do
        for _ , pet in folder:GetChildren() do
            local PlayerName = folder.Name
            local Character = workspace:FindFirstChild(PlayerName)

            for _, descendant in pairs(pet:GetDescendants()) do
                if descendant:IsA("MeshPart") or descendant:IsA("BasePart") then
                    descendant.CanCollide = false
                end
            end

            if Character == nil or not Character:FindFirstChild("HumanoidRootPart") then continue end

            local rayOrigin = Vector3.new(pet.PrimaryPart.Position.X, pet.PrimaryPart.Position.Y + 20 , pet.PrimaryPart.Position.Z)
            local params = RaycastParams.new()
            params.FilterDescendantsInstances = {pet}
            params.FilterType = Enum.RaycastFilterType.Blacklist
            
            local direction = Vector3.new(0, -1, 0) * 100
        
            local ray = workspace:Raycast(rayOrigin, direction, params)
            local FinalCFrame 
            if ray then
                FinalCFrame = CFrame.new(Character.HumanoidRootPart.CFrame.X - 5 , ray.Position.Y + pet.PrimaryPart.Size.Y * 1.5 , Character.HumanoidRootPart.CFrame.Z + 5)
            end
        
            local GoalCF = Character.HumanoidRootPart.CFrame 
            GoalCF = GoalCF * CFrame.Angles(0,math.rad(0),0)
            GoalCF = (GoalCF - GoalCF.LookVector * 5)
            GoalCF = GoalCF * CFrame.Angles(0 , -math.rad(0),0)

            pet.PrimaryPart.AlignPosition.Position = FinalCFrame.Position
            --pet.PrimaryPart.AlignPosition.Position = GoalCF.Position
            pet.PrimaryPart.AlignOrientation.CFrame = GoalCF
         end
     end
 end)

When using the target players position try using the right vector and inverted look vector to find the position of your pet in relation to the direction of the target player.

I don’t really know what you mean by using right vector and invert look vector , can you give me an example?

Hes prob telling to find the behind right player position, e.g

local rootpos = rootpart.Position
local LookVec = rootpart.CFrame.LookVector*-3  --taking the invert look vector
local LeftVec = rootpart.CFrame.RightVector*2
local Pos = rootpos + LookVec + LeftVec
Npc.Humanoid:MoveTo(Pos) --Moving the npc to the position

With MoveTo it doesn’t really work I test it out.

What you mean? why is not working?
MoveTo() accepts a Vector3, and you are getting the Vector3 behind the player, where your NPC should try to MoveTo, @RoloTheDevBunny and @aliaun125 are right

What I mean is I am using AlignPosition since I test it with MoveTo and it didn’t really work how it was suppose to be.

Consider Pos the GoalCF by converting it into Cframe, MoveTo is an example here but it should solve the initial issue


I found the solution why it was not working , thanks anyway for the help!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.