Hey there!
I recently made a small pathfinding script, but there is one problem: the NPC gets stuck on walls and/or corners, without trying to recalculate the path.
Here is an example:
Here is a part of the script I am using, including an attempted fix:
while true do
if not closeToPlayer and not closeToTarget then
local pathParams = {
["AgentHeight"] = 5,
["AgentRadius"] = 2
}
local path = pFS:CreatePath(pathParams)
local succes, errormessage = pcall(function()
if not hasTarget then
path:ComputeAsync(monkey.HumanoidRootPart.Position, hRP.Position)
else
path:ComputeAsync(monkey.HumanoidRootPart.Position, currentTarget.HumanoidRootPart.Position)
end
end)
if succes or path.Status == Enum.PathStatus.Success then
local waypoints = path:GetWaypoints()
for i = 1,5 do
if i <= #waypoints then
if waypoints[i].Action == Enum.PathWaypointAction.Jump then
monkeyNoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
local part = Instance.new("Part", workspace)
part.Shape = Enum.PartType.Ball
part.BrickColor = BrickColor.White()
part.Material = Enum.Material.Neon
part.CanCollide = false
part.Anchored = true
part.Size = Vector3.new(.5,.5,.5)
part.Locked = true
part.Position = waypoints[i].Position
game:GetService("Debris"):AddItem(part, 1)
monkeyNoid:MoveTo(waypoints[i].Position)
monkeyNoid.MoveToFinished:Wait()
end
end
else
warn(errormessage)
monkeyNoid:MoveTo(hRP - monkey.HumanoidRootPart.CFrame.LookVector * 10)
end
end
runS.Heartbeat:Wait()
end
Any help is greatly appreciated!