Search Unity

IGAMEMAKER.COM - Makeroids - Asteroids with Unity3D

Discussion in 'Made With Unity' started by igamemaker, Mar 10, 2011.

  1. igamemaker

    igamemaker

    Joined:
    May 2, 2010
    Posts:
    9
    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.


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

    Let me know what you think.
     
    Last edited: Sep 12, 2012
  2. PolyMad

    PolyMad

    Joined:
    Mar 19, 2009
    Posts:
    2,350
    Spawning asteroids on the player pisses me off!
     
  3. igamemaker

    igamemaker

    Joined:
    May 2, 2010
    Posts:
    9
    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!
     
  4. igamemaker

    igamemaker

    Joined:
    May 2, 2010
    Posts:
    9
    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:
    Code (csharp):
    1.  
    2. int numberOfHugeAsteroidsToSpawn = currentLevel/3;
    3. int numberOfLargeAsteroidsToSpawn = Mathf.Max(5, currentLevel);
    4. for (;numberOfHugeAsteroidsToSpawn>0;numberOfHugeAsteroidsToSpawn--)
    5. {
    6.     Instantiate(HugeAsteroid, new Vector3(Random.value*10.0f-5.0f, Random.value*6.0f-3.0f, 0.0f), Quaternion.identity);
    7. }
    8. for (;numberOfLargeAsteroidsToSpawn>0;numberOfLargeAsteroidsToSpawn--)
    9. {
    10.     Instantiate(LargeAsteroid, new Vector3(Random.value*10.0f-5.0f, Random.value*6.0f-3.0f, 0.0f), Quaternion.identity);
    11. }
    12. ++currentLevel;
    13.  
    With this added function
    Code (csharp):
    1.  
    2. void SafeInstantiate(GameObject toInstance, GameObject toProtect)
    3. {
    4.     // Calculate safe spawning limits
    5.     Vector3 cameraWorldZ = Camera.main.ScreenToWorldPoint(new Vector3(0,0,0));
    6.     Vector3 bottomLeft = Camera.main.ScreenToWorldPoint(new Vector3(0,0,-cameraWorldZ.z));
    7.     Vector3 topRight = Camera.main.ScreenToWorldPoint(new Vector3(Camera.main.pixelWidth,Camera.main.pixelHeight,-cameraWorldZ.z));
    8.  
    9.     bool bSafeLocation = false;
    10.     int numIterations = 0;
    11.     Vector3 spawnLocation;
    12.     do
    13.     {
    14.         numIterations++;
    15.         spawnLocation = new Vector3(Random.Range(bottomLeft.x,topRight.x), Random.Range(bottomLeft.y, topRight.y), 0);
    16.         // Calculate distance between to two centers minus the two extents
    17.         float distance = 1.0f;
    18.        
    19.         if (null != toProtect)
    20.         {
    21.             Vector3.Distance(spawnLocation, toProtect.transform.position);
    22.             distance -= Mathf.Max(toProtect.collider.bounds.extents.x,toProtect.collider.bounds.extents.y);
    23.             distance -= Mathf.Max(toInstance.collider.bounds.extents.x,toInstance.collider.bounds.extents.y);
    24.         }
    25.  
    26.         if (distance>0)
    27.             bSafeLocation = true;
    28.         else
    29.             Debug.Log("IMPACT WOULD HAVE HAPPENED!");
    30.  
    31.     } while (!bSafeLocation  numIterations < 15);
    32.     Instantiate(toInstance, spawnLocation, Quaternion.identity);
    33. }
    34.  
    And changed the old code to look like this
    Code (csharp):
    1.  
    2. // Spawn some asteroids
    3. GameObject yourShip = GameObject.FindWithTag("Player");
    4.  
    5. int numberOfHugeAsteroidsToSpawn = currentLevel/3;
    6. int numberOfLargeAsteroidsToSpawn = Mathf.Max(5, currentLevel);
    7. for (;numberOfHugeAsteroidsToSpawn>0;numberOfHugeAsteroidsToSpawn--)
    8. {
    9.     SafeInstantiate(HugeAsteroid, yourShip);
    10. }
    11. for (;numberOfLargeAsteroidsToSpawn>0;numberOfLargeAsteroidsToSpawn--)
    12. {
    13.     SafeInstantiate(LargeAsteroid, yourShip);
    14. }
    15. ++currentLevel;
    16.  
    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.