I have a spawn system which checks for a Object A to never spawn above or below Object B (it's a top down game).
When spawning an object, I first find an empty space and then spawn the object in that space. During this, I have a while loop for Object A that checks where the chosen space is. If that space is above or below Object B, then it should re-choose the space. This is the while loop (which is inside a script called "spawnObject()"):
if (obj == objectA)
{
while (space.x == objectB.x and space.y == objectB.y - 32 or space.x == objectB.x and space.y == objectB.y + 32)
{
space = findSpace(); //Use script to find another space
}
}
However, sometimes, ObjectA still spawns above or below ObjectB.
Hope that is enough information. Is there anything wrong with the above code?











