# IGAMEMAKER.COM - Makeroids - Asteroids with Unity3D

Just wanted to send out a quick note that I added a new tutorial to my site. This Tutorial is about making a game similar to the classic asteroids. The game is done and you can play it here. The neat thing about this tutorial is that it is going to cover everything from beginning to end including all the audio and art creation. The tools involved include: Audacity, Blender, Silo, Inkscape and of course Unity!

The full project file is currently available on the link above for \$2 and I am in the middle of recording my “how to make it” tutorials.

Check it out the first video here.

https://vimeo.com/20859597

Or come over to my blog to play the game or buy the tutorial if you are interested!

Let me know what you think.

Spawning asteroids on the player pisses me off!

I originally put the invincibility after death to avoid that but it doesn’t catch the case when a new wave comes in. It would probably be best to test for the player before spawning within a certain safety range. I’ll take a look at that and sorry if it pissed you off!

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;
``````

``````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.