#I need help with my Pathfinding System
1 messages · Page 1 of 1 (latest)
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!
bro
s1
cmon
I alr fixed it
for _, waypoint in ipairs(path:GetWaypoints()) do
...
self.Hum:MoveTo(waypoint.Position)
...
end```
you should be able to tell me whats wrong with that
yk this will not help either
your next problem will be the npc lagging behind the player
thats why the npc just chose the straight path
and being too slow to follow
thats what I am fixing now
because movetofinished:wait() being the newb trap that it is
that is why I made it into another function so that I can cancel it anytime
so it becomes smooth
