#I need help with my Pathfinding System

1 messages · Page 1 of 1 (latest)

fast aspen
#

guys I need help with this, so I want an npc which follows the player and if the wall is in the direcction then it just goes beside it and chases the player and doesnt get stuck, but in this script

#
function npcSpawner:CalculatePath(destination, waypointCheck)
    if waypointCheck then
            local path = PathfindingService:CreatePath()
            
            local success, errorMessage = pcall(function()
                path:ComputeAsync(self.Root.Position, destination)
            end)
            if success then
                for _, waypoint in ipairs(path:GetWaypoints()) do
                    if self.CannotAttack then
                        self.Waypoint = nil
                        break
                    end
                    self.Hum:MoveTo(waypoint.Position)
                    if self.Status ~= "Walk" then
                        if self.WalkAnim then
                            self:PlayAnimation("Walk")
                        end
                    end
                end
                self.Hum.MoveToFinished:Connect(function()
                    self.Waypoint = nil
                end)
            else
                warn(errorMessage)
        end

    else


        local path = PathfindingService:CreatePath()

        local success, errorMessage = pcall(function()
            path:ComputeAsync(self.Root.Position, destination)
        end)
        if success then
            for _, waypoint in pairs(path:GetWaypoints()) do
                if self.CannotAttack then
                    break
                end
                self.Hum:MoveTo(waypoint.Position)
                if self.Status ~= "Walk" then
                    if self.WalkAnim then
                        self:PlayAnimation("Walk")
                    end
                end
            end
        else
            warn(errorMessage)
        end
    end
end```

it doesnt really do that, it just walks into the wall and cant move anymore!
#

He is standing behind a wall rn!

fast aspen
#

I alr fixed it

half rapids
#
for _, waypoint in ipairs(path:GetWaypoints()) do
...
  self.Hum:MoveTo(waypoint.Position)
...
end```
#

you should be able to tell me whats wrong with that

fast aspen
half rapids
#

0.o

fast aspen
#

I fixed it

#

it just needed a wait cuz else the roblox simulation will overwrite it

half rapids
fast aspen
#

thats why the npc just chose the straight path

half rapids
#

and being too slow to follow

fast aspen
half rapids
#

because movetofinished:wait() being the newb trap that it is

fast aspen
#

so it becomes smooth

half rapids
#
  • direct moveto when within line of sight
#

gl salute