Hello guys. I’m trying to make NPC which will be able to break walls. For this I decided to use PathfindingLinks with label “WallBreak”. But when It’s went to coding, I understood that IDK how I can get wall, which WaypointLink was used. Can someone tell me, is it possible?
local Target = workspace.Target
local Obstacles = workspace.Obstacles:GetChildren()
local NPC = workspace.NPC
local RunService = game:GetService("RunService")
local PathfindingService = game:GetService("PathfindingService")
local CurrentPath = nil
local Waypoints = {}
local NextWaypointIndex = 0
local ReachedConnection
local BlockedConnection
local function BreakWall(Wall)
Wall:Destroy()
end
local function FollowPath(TargetPos)
local success, errorMessage = pcall(function()
CurrentPath = PathfindingService:CreatePath({
Costs = {
Wall = 20,
BreakWall = 15,
}
})
CurrentPath:ComputeAsync(NPC.Position, TargetPos)
end)
if success then
Waypoints = CurrentPath:GetWaypoints()
NextWaypointIndex = 1
BlockedConnection = CurrentPath.Blocked:Connect(function(BlockedWaypointIndex)
if BlockedWaypointIndex >= NextWaypointIndex then
BlockedConnection:Disconnect()
FollowPath(Target.Position)
end
end)
if not ReachedConnection then
ReachedConnection = RunService.Heartbeat:Connect(function(Delta)
if Waypoints[NextWaypointIndex].Label == "BreakWall" then
--How to get Wall here?
BreakWall(...)
Waypoints[NextWaypointIndex] = PathWaypoint.new(Waypoints[NextWaypointIndex].Position, Waypoints[NextWaypointIndex].Action, "Walk")
end
NPC.Position = NPC.Position + (Waypoints[NextWaypointIndex].Position - NPC.Position).Unit * Delta * 5
if (NPC.Position - Waypoints[NextWaypointIndex].Position).Magnitude <= 1 then
if NextWaypointIndex < #Waypoints then
NextWaypointIndex += 1
elseif NextWaypointIndex >= #Waypoints then
ReachedConnection:Disconnect()
BlockedConnection:Disconnect()
end
end
end)
end
end
end
FollowPath(Target.Position)
