Reputation: 27
Okay, let me do a simple explanation here.
Basically, I have made a simple movement system that makes the enemy move when these 'if statements' are true
for v, k in pairs(EntityList) do
if EntityList[v].y - self.y > 0 then
self.y = self.y + 1
elseif EntityList[v].y - self.y < 0 then
self.y = self.y - 1
end
end
Excuse my shit code. This works fine, except for the fact that when there are two players; ENEMIES move faster since it is moving the enemy twice. It is adding + 1 to the enemy position TWICE.
Okay, we know the problem.. but how can I fix this? I tried to do a weird movement method which got me into playing with negative numbers too...
help D:
Upvotes: 0
Views: 38
Reputation: 11
Move this functionality outside the player object's code. The player object has no business moving enemy objects. That's normally the job of each enemy. If you need better performance and guaranteed coordination to avoid floating point errors, for example, some kind of enemy manager could contain the code instead. That way, when there are multiple instances of the player's code running, there will still be only the one instance of code which moves enemies.
Upvotes: 0