Basically I’m making a system that spawns zombies and handles their pathfinding however my pathfinding code will not work I’m getting no error messages and through some print statements there seems to be something wrong with the waypoints anyone know what it is?
local Zombie = {}
Zombie.__index = Zombie
function Zombie.new(position)
local self = setmetatable({}, Zombie)
self.Model = game.ServerStorage.ZombieModel:Clone()
self.Model.Name = "Zombie"
self.Model.Parent = game.Workspace
self.health = 100
self.speed = 8
self.damage = 10
self.state = "Idle"
print(self.Model)
return self
end
function Zombie:Update()
--What to do depending on the Zombies state
if self.state == "Idle" then
local ReconPoints = game.Workspace.ReconPoints:GetChildren()
local MaxDistance = 50
local ReconTable = {}
--Get all ReconPoints near it and choose one to randomly go to
for _, ReconPoint in pairs(ReconPoints) do
local DistanceFromReconPoint = (ReconPoint.Position - self.Model.HumanoidRootPart.position).Magnitude
if DistanceFromReconPoint < MaxDistance then
table.insert(ReconTable, ReconPoint)
end
end
print(ReconTable)
local ReconPointPickedNum = math.random(1, #ReconTable)
local ReconPointPicked = ReconTable[ReconPointPickedNum]
local path = game:GetService("PathfindingService"):CreatePath()
print(ReconPointPicked)
print(self.Model.HumanoidRootPart.position)
print(ReconPointPicked.Position)
path:ComputeAsync(self.Model.HumanoidRootPart.position, ReconPointPicked.Position)
--If path is possible then go to each waypoint only start gong to the next one when your 5 studs away from current one
if path.Status == Enum.PathStatus.Success then
for _, waypoint in pairs(path:GetWaypoints()) do
self.Model.Humanoid:MoveTo(waypoint.Position)
if waypoint.Action == Enum.PathWaypointAction.Jump then
self.Model.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
end
local goal = false
while goal == false do
task.wait(0.1)
local GoalDistance = (self.Model.HumanoidRootPart.position - waypoint.Position).Magnitude
print(GoalDistance)
if GoalDistance < 5 then
goal = true
end
end
end
else
print("Path not computed")
end
elseif self.state == "Chasing" then
-- Implement chasing behavior
elseif self.state == "Attacking" then
-- Implement attacking behavior
end
print("Not Something")
end
return Zombie