You can write your topic however you want, but you need to answer these questions:
-
I am trying to make a Citizen NPC using Pathfinding Service.
-
The problem is that the the path is calculated correctly and the NPC tried to avoid the wall, but right at the end the calculations goes a little off and makes the NPC slam into the wall. https://gyazo.com/4db964fbe3fdac8eb1d93555c2b3c55d
As you can see in the video, the NPC tries to avoid the wall but misses it just by a few studs. -
I have tried to find a solution across discord servers and the Forum but was unable to find one.
local Citizen = script.Parent
local PathFront2 = game.Workspace.PathFront2
local PathBack1 = game.Workspace.PathBack1
local Humanoid = Citizen.Humanoid
local Torso = script.Parent:FindFirstChild("UpperTorso")
local PathFindingService = game:GetService("PathfindingService")
local PathFront = PathFindingService:CreatePath()
local PathBack = PathFindingService:CreatePath()
local waypoints1
local waypoints2
function onGo()
--before while loop
PathFront.Blocked:Connect(function()
print("Break!")
breakPath = true
end)
--in while loop
PathFront:ComputeAsync(Torso.Position, PathFront2.Position)
if PathFront.Status == Enum.PathStatus.Success then
breakPath = false
waypoints1 = PathFront:GetWaypoints()
local wastedTime = 0
for _, waypoint in ipairs(waypoints1) do
repeat
wastedTime = wastedTime + 1
if(waypoint.Action == Enum.PathWaypointAction.Jump) then
Humanoid.Jump = true
end
if breakPath == true then break end
Humanoid:MoveTo(waypoint.Position)
wait()
until (Torso.Position - waypoint.Position).magnitude < 8 or breakPath == true or wastedTime >= 50
end
end
end```