Looking for help
Posted: Sat Jul 30, 2022 3:47 pm
So I want these creatures to move towards food when it is in their vision, the food is inside of a table and randomly spawned.
Here is the code I used to move the creatures:
function moveCreatures(dt)
for index, creature in ipairs(creatures) do
dir = rand(1, creature.chanceToMove+4)
if dir == 1 and creature.x < gridXCount then
creature.x = creature.x + 1
creature.survive = creature.survive - creature.cost
elseif dir == 2 and creature.x > 2 then
creature.x = creature.x - 1
creature.survive = creature.survive - creature.cost
elseif dir == 3 and creature.y < gridYCount then
creature.y = creature.y + 1
creature.survive = creature.survive - creature.cost
elseif dir == 4 and creature.y > 1 then
creature.y = creature.y - 1
creature.survive = creature.survive - creature.cost
end
end
end
Here is the code I used to move the creatures:
function moveCreatures(dt)
for index, creature in ipairs(creatures) do
dir = rand(1, creature.chanceToMove+4)
if dir == 1 and creature.x < gridXCount then
creature.x = creature.x + 1
creature.survive = creature.survive - creature.cost
elseif dir == 2 and creature.x > 2 then
creature.x = creature.x - 1
creature.survive = creature.survive - creature.cost
elseif dir == 3 and creature.y < gridYCount then
creature.y = creature.y + 1
creature.survive = creature.survive - creature.cost
elseif dir == 4 and creature.y > 1 then
creature.y = creature.y - 1
creature.survive = creature.survive - creature.cost
end
end
end