Search Unity

Unity Invaders

Discussion in 'Made With Unity' started by Eric5h5, May 13, 2007.

  1. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    Note: this thread is old. ;) This is one of the first projects I did in Unity, long ago, but I posted it to the forums here and it has gotten occasional comments and questions ever since. One of those comments prompted me to update it for Unity 5, but when doing so I realized the project was actually quite a mess. Apparently I've learned a thing or two since then, but also back then Unity didn't have a lot of the features it has now...e.g., things like no collision matrix made hacking around with IgnoreCollision necessary. So I redid it from scratch, aside from the graphics/sound, using modern features in Unity 4.6 (since I can't really bear to use the old GUIText/Texture objects now). And yes it works fine in Unity 5, though the physics in the title screen are a little off, at least with b17.

    invaders.png

    Since it's a relatively small project, I thought it might make a decent example of a complete game for newcomers to maybe learn a few things from, so I uploaded the project folder (see links below). I think some things are easier to understand in context, and this ended up covering quite a few areas...2D sprites in a 3D environment (though mostly not "real" sprites since I used material offset animation), particle effects, sound, scoring, physics, multiple camera techniques, layers, a bit of level management, object pooling, simple UI elements, etc.

    There are some elements that are easily tweakable in the inspector (on the "Main Camera" object mostly), but it might make an interesting exercise to expand on the game if anyone feels so inclined. Powerups, different alien behavior, bosses, etc. Right now it's just yer basic Space Invaders.

    Some of the sound effects are modifications of sounds from the Gear Worx Productions "modern weapons and warfare" sound pack (the explosions and ricochets), so please don't reuse those unless you've also bought a license from them. The rest of the stuff is by me (aside from a few publicly-available sound effects), which you can do with as you like.

    Download here for Unity 4.6. (The old junky version is here, though it was updated several times and works with Unity 4.3.)

    --Eric
     
    Last edited: Dec 24, 2014
    Ony likes this.
  2. bronxbomber92

    bronxbomber92

    Joined:
    Nov 11, 2006
    Posts:
    890
    Nicely done! I couldn't get past the coin slot though....


    Naw, j/k, it only took me ten minutes. The game was fun, glad you released the project to :)
     
  3. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    Very cool Eric! The invaders are a little more accurate and trigger happy, than what I remember... but a very good remake of the classic! Well done.
     
  4. Samantha

    Samantha

    Joined:
    Aug 31, 2005
    Posts:
    609
    Excellent job! I found this to be quite addicting, actually. I wanted to keep pumping in virtual quarters to try again. Nicely done!
     
  5. Lallander

    Lallander

    Joined:
    Apr 23, 2006
    Posts:
    429
    Great handling overall. The coin thing took me about 4 - 5 tries before i realized you needed to line up the shadow.

    The invaders do seem much more agressive then the original.
     
  6. forestjohnson

    forestjohnson

    Joined:
    Oct 1, 2005
    Posts:
    1,370
    This is a lot harder than the space invaders I played. A couple things I might change:

    The falling invaders should be able to be shot and also be a hazard to the player.

    Slow down the enemies bullets and make there be less of them, if you want it to be more like the famous space invaders games.

    The game over sequence seems a bit too long?

    I love the coin thing too! Should I be able to skip it with space?

    Just think if you had an actual quarter for each time we have played it so far... :p
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    Me too...I'm not sure why. I mean it's a nearly 30-year old game. :confused: Oh well, at least it got a lot of play-testing....

    When I first implemented the bombing routine, the invaders just bombed randomly. I quickly realized that made it way too easy, but fortunately it was just a matter of a few lines of code to bolt on some proximity logic. Now the program chooses a random number to decide whether to bomb randomly or not. I started at 80% but that was a bit much. ;) I think it's at 50% now, which seemed about right, but if you just change that one number to something lower, that will make it easier. You can also make it so they start dropping 2 bombs at once (the maximum) later on if you like. It's possible they start doing that too early.

    --Eric
     
  8. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,193
    Cool. And rather difficult, actually!
     
  9. VICTOM

    VICTOM

    Joined:
    Aug 28, 2005
    Posts:
    233
    Great remake, much harder than original. I love the damage shake. You can really feel the pain. But level one is too hard ;)

    Cheers,
     
  10. Marble

    Marble

    Joined:
    Aug 29, 2005
    Posts:
    1,193
    That's a really clever way to make destructible 2D objects, Eric!
     
  11. zoul

    zoul

    Joined:
    May 5, 2007
    Posts:
    50
    very well done -- and what a great use of the "modern weapons and warfare" pack ... I personally never thought of using it for something like this ... and check it out ... it works!


    Great job ... and excellent choice for a classic!


    The thing I loved the most, aside from the obvious use of one of our products (heh), was the coin drop ... and the 3d backgrounds ... I also loved the overly pixelated 2d artwork ... excellent work!
     
  12. GWPGearWorx

    GWPGearWorx

    Joined:
    Apr 29, 2007
    Posts:
    320
    That is awesome to hear some of my sounds were put to good use, looks and plays great, addicting little game. Well done, gotta love the classics.
     
  13. DaveyJJ

    DaveyJJ

    Joined:
    Mar 24, 2005
    Posts:
    1,559
    Eric5h5, can I post the web player version on the showcase section of Widget Monkyy Games, please?

    Love it. And agree it's harder than the original (which stole so many of my $0.25 I'd rather not remember).
     
  14. drJones

    drJones

    Joined:
    Oct 19, 2005
    Posts:
    1,352
    haha that's awesome! i'm surprised its in 2D - i'm eager to check out the project files to see how you got that all working (thanks so much for posting them ; )

    go retro!
     
  15. HiggyB

    HiggyB

    Unity Product Evangelist

    Joined:
    Dec 8, 2006
    Posts:
    6,183
    Fun stuff, good work! My only complaints/suggestions:

    1. While I enjoyed the whole "drop the coin in the slot" bit, maybe you can (a) expand the coin slot a bit, it took me 3 tries to get it right (sorry, still drinking my coffee this morning ;P), and (b) have an option to skip it.

    2. Can you have it auto-fire if I just hold down the spacebar? I'm lazy and want it to repeatedly fire if I hold down the fire key.


    Otherwise yes, it is very addictive. It truly does remind me of all those days I spent riding my lil' dirt bike over to the arcade to promptly burn through my entire weekly allowance playing video games... Ahh, good times!
     
  16. nickavv

    nickavv

    Joined:
    Aug 2, 2006
    Posts:
    1,801
    Along the same lines as DaveyJJ, can I put the web player on Unicade? We're going through a dry spell of games of sorts, and this is exceptional. :)
     
  17. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    Thanks for the comments, everyone! Yes, DaveyJJ and Moldorma, you can use it on your websites, but let me add in one or two things since I wasn't thinking about having any distribution outside this topic. So hold off until later this evening, if you would.

    As far as difficulty, I think y'all's arcade skillz are a tad rusty. ;) Let's just say that screenshot was from shortly after I implemented player prefs for the high score, which was the last thing I coded...it's way higher than that now. :) I'll ease back on the difficulty anyway, though. The "game over" part is probably a second too long, but I like having a moment to reflect on my failure before being thrown back to the title screen. OK, I'm weird.

    It would be trivial to have the falling invaders be a hazard (and I certainly thought about it), but that would be changing the gameplay too much from the original. Same deal with autofire...I'm pretty sure you can't do that in the real Space Invaders. So, no. But hey, you've got the source.... ;) And as I mentioned at the end of my (long) first post here, you can skip the coin thing with whatever you've got "fire" set to. Normally space/control.

    --Eric
     
  18. DaveyJJ

    DaveyJJ

    Joined:
    Mar 24, 2005
    Posts:
    1,559
    Absolutely and thanks.

    David
     
  19. yangmeng

    yangmeng

    Joined:
    Dec 5, 2006
    Posts:
    573
    This is great! Thanks for letting people take a look at how it was made. I learned a couple of things just by looking at some of the files in the finder.
    One question - How in the world did you get the standalone player's file size down to 22MB?! I did a test build of a Unity project with one scene and nothing but a camera and it is 40.2 MB! You obviously know something I don't know but really ought to know...
     
  20. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    No I don't. :) I swear...I just hit Command-B...me knows nothing.... I just did a test with an empty scene with a camera, and it came out to 19.3 MB (Universal Binary; PPC or Intel only is nearly half that).

    (I haven't done the additions yet, and now I want to have dinner. Soon. :) )

    --Eric
     
  21. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    4,575
    Turn on strip debug symbols.
     
  22. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    OK, here it is...just a couple of minor differences, but anyone using it on a website please use this version instead of the earlier one. Thanks!

    --Eric
     

    Attached Files:

  23. yangmeng

    yangmeng

    Joined:
    Dec 5, 2006
    Posts:
    573
    Wow, that made a big difference. Thanks. I am glad there was Eric5h5's example to let me know I was doing something wrong.
     
  24. morgansaysthis

    morgansaysthis

    Joined:
    Jan 12, 2007
    Posts:
    245
    haha thats awesome


    i really like the quarter dropping in the beginning, i also like the 8-bit sounds up until your hit and then BOOOOMMMM

    kinda wakes you up



    cool beans man
     
  25. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    I had a request for an updated project folder, so I edited the first post here to include a project that was made with Unity 2.1. Mostly there's not much different: fixed a typo in the fpscounter script that compiled under 1.6 but which 2.1 (correctly) complains about, some slight coding clean-up in some of the scripts, removed the TurnOffParticles script which isn't needed anymore in 2.1. The main difference is some code I added a while ago that allows for streaming when built as a web player target (you can see the results here).

    --Eric
     
  26. S1m0n

    S1m0n

    Joined:
    Aug 20, 2009
    Posts:
    1
    So I'm a newbie and just trying out a few demos etc. I've got a GTX260 graphics card and lots of free memory etc. However, when I run most demos -- e.g. the Invaders demo -- then the Task Manager always shoots up to 100% CPU usage for one of the cores. It also doesn't matter which resolution I choose or which level of graphical quality etc... it always shoots up to 100%. I can maybe understand this for a complicated 3D demo which is pushing the limits but I don't understand it for simple demos like Invaders. But I also don't think that its the Invaders code specifically. I've seen the same 'problem' with tutorial code too. Can anybody explain this? Thanks, Simon
     
  27. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    That's expected behavior...games always try to run as fast as possible; even the most basic Pong clone will "push the limits" (and probably run many thousands of fps on modern hardware). You can turn vertical sync on or use Application.targetFramerate if you want to limit CPU usage.

    --Eric
     
  28. calelogan

    calelogan

    Joined:
    Nov 6, 2009
    Posts:
    6
    THanks for sharing the project folder.

    I'll definitely learn from it.
     
  29. bloodtiger10

    bloodtiger10

    Joined:
    Nov 9, 2008
    Posts:
    619
    what about my track pad I use on my macbook pro ? :D the game was fine to be played with a 1 button mouse, the controls don't even use the mouse besides the coin slot.
     
  30. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    I had a question about the project's compatibility with Unity 2.6; the only real change is that the "splat" texture needs to be marked readable.

    However, seeing as how this has had over 1K downloads, and how I found some interesting things done with it (check this out), I took the opportunity to do some more changes and cleaning up, like removing the obsolete "pipeline" components and so on. Then I fairly heavily edited some of the scripts to better reflect how I currently think scripts should be written, and expanded the comments, so I think they make more sense and are a better resource. (It's also better optimized, so in case 500fps wasn't good enough for you before, it's faster now. ;) )

    You can get the new project folder here. I'd update the original project, but the forum won't let me....

    --Eric
     
  31. Thomas GD

    Thomas GD

    Joined:
    Oct 23, 2009
    Posts:
    103
    Eric can we use this prefab For making an own custom Invader game if I give you credits?
     
  32. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    Sure, go for it.

    --Eric
     
  33. Thomas GD

    Thomas GD

    Joined:
    Oct 23, 2009
    Posts:
    103
    ty eric.
     
  34. futurefreak

    futurefreak

    Joined:
    Mar 18, 2010
    Posts:
    4
    This is AMAZING for several reasons:

    1. it's a really good conversion of the game
    2. the coin start is great - the sound is so very satisfying as the coing goes in.
    3. I've been fiddling with unity for a few weeks now and this is the first proper example I've seen on how to structure a game, with respect to storing the variables, loading levels etc. I was kind of on the right lines in terms of thinking of it this way - but couldn't find any tutorial that says this is how you do it to confirm my thoughts.

    Many thanks!
     
  35. minevr

    minevr

    Joined:
    Mar 4, 2008
    Posts:
    1,015
    We call it : Small bee~~ :p
     
  36. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    Thanks, glad you like it!

    --Eric
     
  37. skeinath

    skeinath

    Joined:
    Aug 9, 2010
    Posts:
    4
    Eric,

    I emailed you via your website's contact form before seeing this forum topic.

    Thanks for giving your project files out. My students and I will learn tons!!!
     
  38. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    You're welcome...it probably wouldn't be a bad idea for me to link to this topic from my web site.

    --Eric
     
  39. Jsb_7

    Jsb_7

    Joined:
    Dec 7, 2010
    Posts:
    5
    Hey Eric! I know it's been more than a year since your last post even longer since you worked on this game, but I have a request. It's probably been asked of you before denied for various reasons(I think mine is easier to work around leaves more flexibility for you :) assuming similar questions have been asked b4). I was wondering if you, a coworker, or some1 else could do a tutorial on this game or something like this(just as deep scripting, 2D implementation, graphics similar in style, way to go about it)? If not that then could you or some1 else debunk this game by explaining the more advanced concepts of it how they can be implemented outside of the context of this game in a variety of situations( if there are different ways to do it such as different ways to script it)? I don't care how much time is spent on it(overall /or per day) as long as it helps me others learn the deeper fundamentals of game programming Unity 3D. It's not like I'm asking you to make a game for me. I just want to learn self-teaching methods (without books) high school game programming classes can only get you so far. If you can't do any of these things then could you redirect me to some1 who'd be willing to or give me another option to understand this better? Without breaking it down or starting from the beginning having limited knowledge I find it at least slightly difficult if not very difficult at times time consuming to figure it out. I don't want it to be time consuming for you of course(definition of time consuming in this sentence would be too much time spent on it when it could have been done faster and/or better things for person to do). Perhaps, you could upload videos of the process of making it so I others could watch them. This of course assumes you videotaped making the game while you were making it. Thanks for any help you can give!

    Sorry for the LOOOOOOOOOONG post
    -Jason
     
  40. Landern

    Landern

    Joined:
    Dec 21, 2008
    Posts:
    354
    I hope you pay Eric a consulting fee for what you're asking. :)
     
  41. MetaMythril

    MetaMythril

    Joined:
    May 5, 2010
    Posts:
    150
    Not going to quote that entire painful wall of text. You are saying "I'm not asking you to make a game", but that is exactly what he has done, and provided the entire source of it at that. Learn the basics and you should be able to pull this game apart and see what is going on. The scripts are well commented and are pretty straight forward. I'm new to Unity and I'm able to follow it. You may want to look at the videos over at http://unity3dstudent.com/ to get you started, it's where I did.

    All that being said, Eric, I can not for the life of me figure out where you are assigning the "hole" variable in the BunkerControl script file. I was porting the script to C# to try and destroy a texture like you are doing with the bunkers but I'm not seeing where the hole is assigned a texture to be used in the CheckAlpha method later.

    Not sure what I'm missing with this, but in any case, thanks so much for making this, I've learned a lot for 2.5D game stuff just from this.
     
  42. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    The BunkerControl script is attached to the _Manager object, and the "hole" texture is assigned in the inspector. You can use the search feature to find which objects scripts are attached to. (I updated the project for Unity 3.2 here, just so it imports cleanly; I didn't make any changes but there were some messages about stuff it was apparently cleaning up in the upgrade process.)

    --Eric
     
  43. MetaMythril

    MetaMythril

    Joined:
    May 5, 2010
    Posts:
    150
    Found it, I didn't scroll past the Audio Source section to see the Bunker Control script section below it. I'm trying to understand how the search feature works to find the objects a script is attached to as you mentioned for future reference but the small search boxes on the Scene/Hierarchy/Project views don't seem to do the trick. Couldn't find anything in the manual about it either.

    Any thoughts of what I may be doing wrong? Thanks again for the help Eric!
     
  44. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    Type in "BunkerControl" in the Hierarchy search box and every object using it is shown (in this case, just the _Manager object).

    --Eric
     
  45. MetaMythril

    MetaMythril

    Joined:
    May 5, 2010
    Posts:
    150
    Ah, I understand now. I needed the whole word in there. When I was seeing objects disappear as I typed, I was thinking it was like a type of "Google live search" catching partials. Funny how people perceive things after seeing them a certain way.

    Thanks once again for your great help, this will definitely speed my learning of Unity3D. I can't wait to have my first game ready to show to the community. All in due time though. :)
     
  46. MetaMythril

    MetaMythril

    Joined:
    May 5, 2010
    Posts:
    150
  47. U7Games

    U7Games

    Joined:
    May 21, 2011
    Posts:
    943
    Eric5h5, i have come here by searching "how to shake camera unity3d", what script can i check to see how to shake the player cam?..

    Greetings
     
  48. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,089
    It's in the InvaderControl script.

    --Eric
     
  49. Rush-Rage-Games

    Rush-Rage-Games

    Joined:
    Sep 9, 2010
    Posts:
    1,998
    Thanks Eric for the super cool project!
     
  50. U7Games

    U7Games

    Joined:
    May 21, 2011
    Posts:
    943
    TYhanks!