hey again, helpful devforum. i’ve configured my zombie’s code to attempt to break down boards that are in the way of it’s path to the player. it’s not doing too well, though. dunno how to explain it.
the zombie only starts the path to the boards when i walk infront of the boards. the zombie doesnt have any special eyesight mechanisms. just magnitude.
-- main NPC behavior loop with path obstruction handling
local function startNPCBehavior()
while npcHum.Health > 0 do
local closestPlayer = getClosestPlayer()
if closestPlayer then
if not isChasingPlayer then
isChasingPlayer = true
npcHum.WalkSpeed = speed
playSound(spottedSound)
print("Player spotted!")
end
-- Check for a blocking board
local blockingBoard = getBlockingBoard(closestPlayer.HumanoidRootPart.Position)
if blockingBoard then
-- Attempt to move towards the blocking board
local pathSuccess, path = pcall(function()
return path:Run(blockingBoard.Position)
end)
if not pathSuccess or not path then
print("Path to board blocked, unable to reach.")
else
print("Moving towards blocking board at:", blockingBoard.Position)
-- Damage the board if within range
if (hrp.Position - blockingBoard.Position).Magnitude <= DAMAGE_RANGE then
local boardHealth = blockingBoard:GetAttribute("Health")
if boardHealth then
blockingBoard:SetAttribute("Health", boardHealth - DAMAGE_AMOUNT)
local sound = damageSounds[math.random(1, #damageSounds)]
playSound(sound)
end
end
end
else
-- Move towards the player if no blocking board is detected
local pathSuccess, path = pcall(function()
return path:Run(closestPlayer.HumanoidRootPart.Position)
end)
if not pathSuccess or not path then
print("Path to player blocked, unable to reach.")
else
print("Chasing player at position:", closestPlayer.HumanoidRootPart.Position)
end
end
else
if isChasingPlayer then
isChasingPlayer = false
npcHum.WalkSpeed = wanderSpeed
playSound(lostSound)
print("Player lost..")
end
-- Wander behavior when no player is detected
local wanderPosition = hrp.Position + Vector3.new(math.random(-20, 25), 0, math.random(-20, 25))
local pathSuccess, path = pcall(function()
return path:Run(wanderPosition)
end)
if not pathSuccess or not path then
print("Path to wander position blocked, unable to reach.")
else
print("Wandering to position:", wanderPosition)
end
task.wait(wanderDelay)
end
applyGroupRepulsion()
damageNearbyTargets() -- Call the range-based damage function
task.wait(0.1)
end
im using SimplePath module btw. lmk if you need the full script. tysm
It is probably due to it not being able to find a path until you step infront of it, meaning its probably an issue with the module.
i havent used this module myself so im not sure of any solutions, neither am i the greatest at pathfinding.
try messing with the modules code, or maybe contacting the original developer of the module if you cant.
like i said beforehand, its most likley due to it not being able to find a diret oath until you step infront of the planks, try printing whether it has a path or not, and/or marking the current path it has.
yeah it uses raycasts for getting boards. thanks for your suggestions
-- Function to detect blocking boards in the zombie's path
local function getBlockingBoard(targetPosition)
local direction = (targetPosition - hrp.Position).Unit
local ray = Ray.new(hrp.Position, direction * rangeToChase)
local hitPart, hitPosition = workspace:FindPartOnRayWithIgnoreList(ray, {npc, workspace.Zombies})
if hitPart and hitPart:GetAttribute("Built") == true and hitPart:GetAttribute("Health") then
return hitPart
end
return nil
end
-- Function to get the closest player
local function getClosestPlayer()
local closestPlayer = nil
local shortestDistance = rangeToChase
for _, player in pairs(players:GetPlayers()) do
local character = player.Character
if character and character:FindFirstChild("HumanoidRootPart") and player.Team == aliveTeam then
local distance = (character.HumanoidRootPart.Position - hrp.Position).Magnitude
if distance < shortestDistance then
closestPlayer = character
shortestDistance = distance
end
end
end
return closestPlayer
end
thats most likely the issue then then a racast wouldnt get the board unless it directly hits it
something i’d try is getting the closest board set to the player its attempting to chase and then have it pathfind to that if there isnt a clear path
though that would cause it to go a longer way around rather then straight through ther board if you do specificly what i said
another thing you can do is jsut pathfind to the player with the pathfinding ignoring the boards,
and when the zombie gets close, then starts breaking the boards
so i found out how to make zombies ignore the boards (inserting a pathfinding modifier into the boards), but the zombies try and jump on top of the boards now. how can i fix this? is there a better way to make them ignore the boards?
the problem is that simplepath has an option where if its “stuck” it will jump, i also believe certain path params tell the npc to jump as part of a generated path, in this case, its likely the stuck contingency playing.