I have written up a fix for this and thought I would post it here. I haven’t updated the online game with it but may later today.

In GameLogicScript.cs I changed the following:

```
int numberOfHugeAsteroidsToSpawn = currentLevel/3;
int numberOfLargeAsteroidsToSpawn = Mathf.Max(5, currentLevel);
for (;numberOfHugeAsteroidsToSpawn>0;numberOfHugeAsteroidsToSpawn--)
{
Instantiate(HugeAsteroid, new Vector3(Random.value*10.0f-5.0f, Random.value*6.0f-3.0f, 0.0f), Quaternion.identity);
}
for (;numberOfLargeAsteroidsToSpawn>0;numberOfLargeAsteroidsToSpawn--)
{
Instantiate(LargeAsteroid, new Vector3(Random.value*10.0f-5.0f, Random.value*6.0f-3.0f, 0.0f), Quaternion.identity);
}
++currentLevel;
```

With this added function

```
void SafeInstantiate(GameObject toInstance, GameObject toProtect)
{
// Calculate safe spawning limits
Vector3 cameraWorldZ = Camera.main.ScreenToWorldPoint(new Vector3(0,0,0));
Vector3 bottomLeft = Camera.main.ScreenToWorldPoint(new Vector3(0,0,-cameraWorldZ.z));
Vector3 topRight = Camera.main.ScreenToWorldPoint(new Vector3(Camera.main.pixelWidth,Camera.main.pixelHeight,-cameraWorldZ.z));
bool bSafeLocation = false;
int numIterations = 0;
Vector3 spawnLocation;
do
{
numIterations++;
spawnLocation = new Vector3(Random.Range(bottomLeft.x,topRight.x), Random.Range(bottomLeft.y, topRight.y), 0);
// Calculate distance between to two centers minus the two extents
float distance = 1.0f;
if (null != toProtect)
{
Vector3.Distance(spawnLocation, toProtect.transform.position);
distance -= Mathf.Max(toProtect.collider.bounds.extents.x,toProtect.collider.bounds.extents.y);
distance -= Mathf.Max(toInstance.collider.bounds.extents.x,toInstance.collider.bounds.extents.y);
}
if (distance>0)
bSafeLocation = true;
else
Debug.Log("IMPACT WOULD HAVE HAPPENED!");
} while (!bSafeLocation numIterations < 15);
Instantiate(toInstance, spawnLocation, Quaternion.identity);
}
```

And changed the old code to look like this

```
// Spawn some asteroids
GameObject yourShip = GameObject.FindWithTag("Player");
int numberOfHugeAsteroidsToSpawn = currentLevel/3;
int numberOfLargeAsteroidsToSpawn = Mathf.Max(5, currentLevel);
for (;numberOfHugeAsteroidsToSpawn>0;numberOfHugeAsteroidsToSpawn--)
{
SafeInstantiate(HugeAsteroid, yourShip);
}
for (;numberOfLargeAsteroidsToSpawn>0;numberOfLargeAsteroidsToSpawn--)
{
SafeInstantiate(LargeAsteroid, yourShip);
}
++currentLevel;
```

Now the only case that is still there is if you spawn your ship over an asteroid and don’t move off during your invincibility.