in the screenshot it goes back and fourth between the points infront and behind it, how can I make it choose one direction to go in and find the player, how it works is it find cloest point to the player, (tehre’s raycast checks so it doesn’t use a point going through a wall) scriptL:

local VectorPoints = {}
local function CreatePoint(Offset)
local Point = origin.Position+Offset
table.insert(VectorPoints,Point)
local p = Instance.new("Part")
p.Anchored = true
p.Position = Point
p.Size = Vector3.new(.5,.5,.5)
p.CanCollide = false
p.CanQuery = false
p.CanTouch = false
p.Parent = workspace
game.Debris:AddItem(p,.1)
end
CreatePoint(Vector3.new(5.5,0,0))
CreatePoint(Vector3.new(-5,0,0))
CreatePoint(Vector3.new(0,0,5.5))
CreatePoint(Vector3.new(0,0,-5))
local Closest
local ceckSize = 5
for i,v in VectorPoints do
if Closest == nil then
Closest = v
else
if (destination - v).magnitude < (Closest - destination).magnitude and #workspace:GetPartBoundsInBox(CFrame.new(v),Vector3.new(ceckSize,ceckSize,ceckSize))<=0 then
Closest = v
end
end
end
if Closest then
humanoid.WalkToPoint = Closest
end
1 Like
instead of going aroud the box it goes back and 4th
1 Like
finding cloest player (destination argument in followpath function,)
while task.wait(.05) do
local nearestPlayer, nearestDistance
for _,v in workspace:GetDescendants() do
if v:IsA("Humanoid") and not v.Parent:FindFirstChild("ZombieAI") and v.Parent:FindFirstChild("Head") and game.Players:FindFirstChild(v.Parent.Name) and v.Parent:FindFirstChildWhichIsA("Humanoid").Health>0 then
local distance = game.Players:FindFirstChild(v.Parent.Name):DistanceFromCharacter(origin.Position)
if not character or
distance > Range or
(nearestDistance and distance >= nearestDistance)
then
continue
end
nearestDistance = distance
nearestPlayer = v.Parent.Head
end
end
if nearestPlayer then
CurrentTarget = nearestPlayer
followPath(nearestPlayer.Position)
if origin:GetNetworkOwner()~=game.Players:FindFirstChild(nearestPlayer.Parent.Name) then
origin:SetNetworkOwner(game.Players:FindFirstChild(nearestPlayer.Parent.Name))
end
end
end
1 Like
this also sets the networkownership b ecause if it didn’t then the player could be attacked when the zombie is like 10 studs away, so far it’s been working perfectly now I just have to have help or figuring out the pathfinding since robloxs pathfinding is not reliable
1 Like
I admit I skimmed through the post but are you recalculating the path often? If you are, the zombie is probably generating another path which sends it in the other direction constantly. Just generate one path until you NEED to generate another.
I aina’t even generating paths I’m using nodes around the zombie with an offset and making the zombie move to the nodes position that is cloest to the target destination, it uses no path or stff like that
idk how to generate a path either using hte current system or any paths at all
I still need help foor this