At this moment, this is my current path finding function. It starts by taking the information from each enemy where it is. This function takes up a lot of time, so I try to only use it only when I need to. The function then searches through the entire map to find that certain enemies goal. In most cases, the enemies are searching for the “RV”. When that function finds the “Rv” it reports back its current position. Those to values are compared and then stored with the enemy. By the end of this function the enemy know how far to move in what directions. As the enemy begins to move, it changes these stored values. When it finds it goal, it finally stops moving.
function PathFinding(index)
y = en[index][1]
x = en[index][2]
for i = 1, math.floor(wx) do –y
for l = 1, wy do — x
if en[index][7] == 2 then
–this will let the enemy follow you
if map[i][l] == en[index][7] then
en[index][9][1] = l – x
en[index][9][2] = i – y
end
else
–build in attack barriers
int = math.random(1, 10)
if map1[i][l] == en[index][7] then
en[index][9][1] = l – x
en[index][9][2] = i – y
end
end
end
end
end