How to break current path and start moving on new path after the player moves their position?

I’m making a chase ai, this one can turn corners. (Hopefully)

However, it’s sort of working, but the dude zig zags if you don’t break the old paths and he gets stuck. How do I check when the players position has moved so I can break the old path and recompute?

Code:

if (not Functions:VisionCheck(Target, HumanoidRootPart, self)) then
	if (self.LockTargets) then
		local TargetRootPart : BasePart = Target.Character:WaitForChild("HumanoidRootPart");

		StopRegularMovement = true;
		MainPath:ComputeAsync(HumanoidRootPart.Position, TargetRootPart.Position);

		local Waypoints = MainPath:GetWaypoints();

		Functions:DisplayPath(Waypoints);

		for _, Waypoint : PathWaypoint in (Waypoints) do
			if (Functions:VisionCheck(Target, HumanoidRootPart, self)) then
				StopRegularMovement = false;
				break;
			else
				-- check if player moved here, if so then break and recompute
			end
			Humanoid:MoveTo(Waypoint.Position);
			task.wait(Functions:PredictWalkTime(Waypoint, HumanoidRootPart, Humanoid) - 0.4);
		end
	else
		FoundTarget = false;
		PauseLoop = false;
		ChaseSequenceR:FireClient(Target, false);
		break;
	end
end

nvm, fixed this by checking the distance between the end point and the targets hrp

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.