So basically im working on a pathfinding system using the new PathFindingService.
If i add Humanoid.MoveToFinished:Wait() after using Humanoid:MoveTo(waypoint) it works but if i move to another direction NPC doesn’t changes his direction and just keep going on his path so this makes a laggy look.
robloxapp-20240801-1425419.wmv (1.9 MB)
If i don’t add Humanoid.MoveToFinished:Wait() after the Humanoid:MoveTo(waypoint) it is smoother but this time it doesn’t listens to pathfinding parameters such as climbing, costs etc.
robloxapp-20240801-1426247.wmv (2.5 MB)
Here is the code:
local function FollowPath()
local path = pFS:CreatePath(
{
AgentHeight = 5;
AgentRadius = 2;
AgentCanJump = true;
AgentCanClimb = true;
Costs = {
DangerZone = math.huge;
}
})
local success, errorMessage = pcall(function()
path:ComputeAsync(character.PrimaryPart.Position, enemyRoot.Position)
end)
local nextWaypointIndex, reachedConnection, blockedConnection
if success and path.Status == Enum.PathStatus.Success then
local waypoints = path:GetWaypoints()
local startTime = tick()
for ind, wp in pairs(waypoints) do
if ind ~= 1 then
selfHum:MoveTo(wp.Position)
selfHum.MoveToFinished:Wait()
if wp.Action == Enum.PathWaypointAction.Jump then
selfHum:ChangeState(Enum.HumanoidStateType.Jumping)
end
end
end
else
warn("failed")
FollowPath()
end
end
FollowPath()
–