• Nextbot fails to create path
    2 replies, posted
I have a nextbot that I want to follow a "recruiter" but when I try to create a new path for it to follow, it doesn't actually create one, if I try to check if it is valid, it returns false. Here is the code: function MercenaryFollowRecruiter(self, idleAnim)     if self.Recruited and IsValid(self.Recruiter) then         local options = options or {}         local pathRecruiter = Path( "Chase" )         local playerPosition = self.Recruiter:GetPos()         if ((math.Distance(self.Recruiter:GetPos().x,self.Recruiter:GetPos().y,self:GetPos().x,self:GetPos().y) >= self.StopDistance)) then             pathRecruiter:SetMinLookAheadDistance( options.lookahead or 5 )             pathRecruiter:SetGoalTolerance( options.tolerance or self.StopDistance  )             if (pathRecruiter:IsValid()) then                 pathRecruiter:Compute( self, playerPosition )      -- Compute the path towards the enemy's position                 pathRecruiter:Update(self)             end             if self:HaveTarget() then                 pathRecruiter:SetGoalTolerance(options.tolerance or 10000)                 self.loco:SetMaxYawRate(500)                 self.loco:FaceTowards(self.Target:GetPos())             end             if (!self.Recruiter:Alive()) then                 net.Start("CloseUI")                 net.Send(self.Recruiter)                 self.loco:SetDesiredSpeed(0)                 self:Remove()                 net.Start("Dead")                 net.Send(self.Recruiter)             end             if ( !pathRecruiter:IsValid() ) then                 coroutine.yield()             end             while ( pathRecruiter:IsValid() ) do                 if IsValid(self) and ( pathRecruiter:GetAge() > 10000 ) and (!self:HaveTarget()) then                 -- Since we are following the player we have to constantly remake the path                     pathRecruiter:Compute( self, playerPosition )-- Compute the path towards the enemy's position again                 end                 pathRecruiter:Update( self )                            -- This function moves the bot along the path                 if ( options.draw ) and (!IsValid(self.Target)) then pathRecruiter:Draw() end                 -- If we're stuck then call the HandleStuck function and abandon                 if IsValid(self) and ( self.loco:IsStuck() ) then                     self.loco:ClearStuck()                     coroutine.yield()                     return "stuck"                 end             end             coroutine.yield()             return "ok"         elseif (self.Recruiter:GetPos().x - self:GetPos().x <= 120) or (self.Recruiter:GetPos().y - self:GetPos().y <= 120) then             self:StartActivity(idleAnim)             coroutine.yield()         else             coroutine.yield()         end         coroutine.yield()     end Ignore the lack of an end at the end of the function, the forum wouldn't let me put it for some reason, but no errors are thrown. The bot just stays still and can't follow the player because the path is not valid, there is a proper navmesh on the map, and I have a similar function to chase enemies, and that works using a nearly identical system.
So I found out the problem is stemming from the path:Compute( ) function, not sure why though, the path won't return true till it has an actual path, not just the object, but anyway. If I remove the if statement for the path:IsValid( ) then it crashes when it tries to compute the path.
Update: I have found the solution, the issue was not the path being created, nor the Compute function itself, at least the one I thought it was, it was in the while loop, and it was due to the coroutine yields causing fatal errors. For future reference, check your loop endings.
Sorry, you need to Log In to post a reply to this thread.