Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

My AI only moves to the first node?

Asked by 10 years ago

The following is an AI for a zombie pathfinding system that moves the zombie along Vector3 coordinates dictated by the real brains behind my pathfinding system (an A* solution). My problem is that, even though I put in a section to deal with this problem, the zombie only moves to the first Vector3 value given.

Can anyone see my mistake/oversight?

print("ZOMBIE PATHFINDING AI: PATHFINDING INITIATED")
firsttime = true

while wait() do
target = script.Parent.nearestTorso.Value
print("ZOMBIE PATHFINDING AI: TARGET FOUND")
targetPath = _G.generatePath(script.Parent.Torso.Position, target.Position, true)
print("ZOMBIE PATHFINDING AI: PATH TO TARGET CALCULATED")
numberOfNodes = 0
for Index, Child in pairs(targetPath) do
numberOfNodes = numberOfNodes + 1
end
print("ZOMBIE PATHFINDING AI: PATH COMPLEXITY = "..tostring(numberOfNodes))
--  y = 1
--  for Index, Child in pairs(targetPath) do
if targetPath then
if firsttime == true then
script.Parent.Zombie:MoveTo(targetPath[1].Value, target)
print("ZOMBIE PATHFINDING AI: MOVING TO VECTOR3 POSITION ["..tostring(targetPath[1].Value).."]")
wait(8/script.Parent.Zombie.WalkSpeed + 0.1)
firsttime = false
else
script.Parent.Zombie:MoveTo(targetPath[2].Value, target)
print("ZOMBIE PATHFINDING AI: MOVING TO VECTOR3 POSITION ["..tostring(targetPath[2].Value).."]")
wait(8/script.Parent.Zombie.WalkSpeed + 0.3)
end
else
print("ZOMBIE PATHFINDING AI: NO SUITABLE VECTOR3 NODE FOUND")
wait(0.5)
print("ZOMBIE PATHFINDING AI: REBOOTING...")
script.Disabled = true
end
--   repeat wait() until (targetPath[y].Value - script.Parent.Torso.Position).magnitude < 6
--  y = y + 1
--  end
print("ZOMBIE PATHFINDING AI: PATHFINDING FUNCTION HAS LOOPED")
end

If it's helpful, I continuously get

ZOMBIE PATHFINDING AI: PATH TO TARGET CALCULATED ZOMBIE PATHFINDING AI: PATH COMPLEXITY = 20ZOMBIE PATHFINDING AI: MOVING TO VECTOR3 POSITION [118.600006, 15.1999998, 48]

to print out from the output.

Thanks in advance

0
Please try to make the title reflect the question, or at least the contents of it. Thanks. User#2 0 — 10y
0
How do I 'bump' my post? Through a comment like this? ChiefWildin 295 — 10y

1 answer

Log in to vote
0
Answered by 10 years ago

I got two solutions to tis problem.

1: Maybe your positioning blocks may be off, reposition them or if not then that's good.

2: Something with your code is not working in the first section. Go to studio and play the game and see the problem In output.

Sorry if I wasn't able to give the answer you desire, but this is what I got.

0
The positioning is precise and exact, and my code is working fine, I'm just not doing it the right way. Which is what I'm asking for. ChiefWildin 295 — 10y
Ad

Answer this question