Friday, 18 February 2011

Day 7 - Billiard Ball Collisions

Using the zip file from Day 6 we can get quickly up to speed. Open the project and away we go...

Today we will add another biliard ball and see them colllide.

  1. Click on the Day 5 scene in the Project pane. All the stuff from the last lesson should appear.
  2. In the hierarchy pane select the sphere/ball
  3. Change the Sphere Collider material properties to "Rubber" in the inspector pane
  4. If you run this the ball plops onto the table with no bounce. That's how you'd expect a billiard ball to react - so far so good. But we need to put the ball on the table rather than drop it.
  5. Change the Y position of the ball to -9.4 Run and see that the ball is on the table.
  6. Have a play with the view settings(this is the compass type icon in the top right of the scene window) so you can view the scene from different angles i.e Top, Right, Left, Perspective etc
  7. We need another ball so select the sphere in the hierarchy pane and right click. The select duplicate. A new sphere will appear in the hierarchy. 
  8. Select the new one. Right Click and rename it to "Ball2" - then move the ball to the side so the settings are x=-2, y=-9, z =4
  9. Run this and you will see 2 little dicky birds sat on a bird table....erm...I mean 2 billiard balls on a billiard table.
  10. Now we need to move one of the balls and crash it into the other! We do this with a nice script :-)
  11. Click the Create button in the Project pane and select "JavaScript" - a new script will appear in the project called "NewBehaviourScript"
  12. Open up this script and copy and paste in the following...

    var oneShot : boolean = false;
    function  Update  () {

     if (! oneShot){
          rigidbody.AddForce(200,0,0, ForceMode.Force); 
          oneShot = true;
       }
    }
  13. This adds a one time force (in the x-dirn) to a ball but first we need to assign the script to an object....
  14. In the project pane drag the script onto the first ball (sphere) - this associates the script with that ball. 
  15. RUN the game and you'll see the balls colliding!
  16. You can now play with the masses of the balls, the force applied and direction and see if you can make the physics of the balls more billiard like! 
  17. Another setting(s) to tweak is the bounciness of the Physic Materials in the project pane (in the Standard Assets folder).
  18. Also have a play with the camera settings to get a nice view of the table. You could try and make the camera projection ORTHOGRAPHIC and have it looking down onto the table from overhead. This will make it a lovely 2d game with 3d rolling textures!

    Here is the final project files for the day....http://www.mediafire.com/?veola5ynbynqya4

Wednesday, 16 February 2011

Day 6 - Big and Bouncy!

Following on from yesterday...

  1. First lets add some light cos it all looks a bit crap dull....
    MENU -> GAMEOBJECT ->  Create Other -> Directional Light

    Hopefully this will light up the scene and when you run the game it will make things look better.
  2. Have a play adjusting the Rotation properties of the Light in the Inspector panel on the right (make sure you click the light in the Hierarchy first to select it. OR you can use the rotate tool just below the top menu - the 2 arrows thinggy!)
  3. Let's create a table for the ball to fall on. MENU -> GAMEOBJECT ->  Create Other -> Cube.
    In the inspector panel change the Scale of the cube to X=10, Y=0.1, Z=10  - That now looks like a table top (ermm yeah)
  4. Move the table under the ball a little way. In the inspector panel for the cube set  Position to x =0, y=-10, z=4
  5. Run the game using the Play Arrow icon. The ball drops onto the table!
  6. We can now move the camera back to get a better look of things. Click the camera in the hierarchy to select it. In the properties pane set Position to x=0, y=-8, z=-7.  Run again.

    That's better. Have a play with the camera to get a position you like. Hmmm nice.
  7. Finally today - click the sphere/ball to select it. In the Inpsector pane find the Sphere Collider section. Click the small circle on the right of the material row.A pop up will appear and select BOUNCY!
  8. Run the game and WOW! The ball bounces. Again have a play selecting different materials for the Sphere Collider and see what happens.
     
 The project at the end of this section can be downloaded here...
http://www.mediafire.com/?doez6y11s40c6qs

Hopefully that works!

Monday, 14 February 2011

Day 5 - My Balls have Dropped!

So far we've done a little work on GUIs with Unity 3d. Let's be honest this is pretty shite boring so let's get into some 3d stuff today.

First we need to grab a pool ball texture. (I typed "pool ball texture" into google and clicked images) something like this will do.

 Save this file to your computer.

  • Fire up Unity and create a new project. Make sure you tick the package box "Physic : Materials.unityPackage". Call the new project "poolballDemo" or something like that.
  • MENU -> GAMEOBJECT -> Create Other -> Sphere
  • MENU -> FILE -> Save Scene As "poolballScene" or whatever.
  • MENU -> ASSETS -> Import New Asset.. -> and browse to the texture you downloaded above.
  • This texture will appear in the project window. Drag this onto the sphere and you should see the texture on the ball in the main display window.
  • Click on the sphere and MENU-> COMPONENT -> Physics -> Rigid Body.  In the Inspector pane you will see this new Rigid Body info appear.
  • Click on the Camera in the Hierarchy pane and change the Transform Position of the camera in the Inspector Pane (on the right). Set X = 0, Y=-8, Z=0   This will allow us to see the ball better.

    Click the RUN arrow.....
Youu should see a pool ball falling from the sky!

Now save your work :-) 

Tomorrow and onwards we will add another ball, create the Pool table for our balls to sit on (ooerrr!), a cushion (that's a rail you N.Americans!) and get some collisions going!

Please follow us on Twitter at  http://twitter.com/unitynovice

Friday, 11 February 2011

Day 4 - Definitions, Variables and Random Numbers

Yesterday we created a GameObject, a Scene and a Script. Let's quickly look at the definition of these from the Unity site...

  • Scenes contain the objects of your game. They can be used to create a main menu, individual levels, and anything else. Think of each unique Scene file as a unique level. Scenes definition
  • GameObjects are the most important objects in Unity. It is very important to understand what a GameObject is. OH GREAT! ....and I wanted an easy day...GameObjects are containers. They are empty boxes which can hold the different pieces that make up[your game].BETTER! See here for full definition GameObjects definition
  • You can add additional functionality to your GameObjects by using Scripts. MAKES SENSE!
So using my limited knowledge so far I'd say .....a Game is made up of Scenes, a GameObject resides in a Scene and contains the main blocks of your game (i.e a Sphere/Ball). A script can bring this block to life by moving it about and crashing into a wall. WALLOP!

Enough about boring old definitions let's do something creative...

Using the Hello World example yesterday let's have a quick play with the script we created. Fire up Unity and open the example. Click on the scene and open up the script.

LET'S MAKE THINGS PERSONAL!  (You Stink! no! not like that!.....)

Change the code to the following:-  (new bits highlighted in BOLD)

var myName = "Unity Novice";
function OnGUI () {
    // Make a background box
    GUI.Box (Rect (10,10,100,40), myName);
}

You have created a variable here with your name in it and displayed it out to the screen.

Run the game (click the Play arrow) and you'll see your name (or mine if you forgot to put your name in!)

Now this may not be very exciting but trust me when I learned BASIC on the BBC Micro 30 years ago this is the sort of shit you'd get off on!

One thing about the scripts I wanted to discover is when and how often is OnGUI() called? Just once or every so often? I decided to combine a couple of quick experiments here to see.

All good games need random numbers so let's see how these are generated...

Change your script to...

var myName = "Henry VIII";
function OnGUI () {
    // create random Number from 0-100
    var myNum:int = Random.Range(0, 100);
    // display variables
    GUI.Box (Rect (10,10,100,40), myName);
    GUI.Box (Rect (10,50,100,40), myNum.ToString());
}

Now run it!

As you can see the random number changes every fraction of a second so we can deduce that OnGui() is called every frame or so. Nice.

Please note that the random number is an integer and needs converting to a string before being displayed using ToString()

That is enough excitement for now. Have a play with the scripts and see where you get. Try adding more boxes and maybe a button! 

Thursday, 10 February 2011

Day 3 - Hello World!

Coming from a Flash web background (and having a crap broadband connection) I'm obsessed at having as small a size as possible when creating a game. One initial reservation I have of Unity 3D is just how big are these final game files going to get? The word "3D" implies to me megabytes of huge polygon-laden models but I'm sure I'm just being paranoid. Let's crack on...

The first thing all crap programmers do is create a Hello World program.So let's do that and we can publish the file to web and see just how big it is!

Again I am a complete novice at Unity so let's have a play together and see where we get...

1. Fire up Unity - a huge demo seems to load up for me. Far too complicated for beginners so let's ditch that.

2. MENU - File -> New Project....

3. Browse to somewhere you want to put your files and call the file "HelloWorld" - so something like
"C:\Users\myusername\Documents\HelloWorld". Click Create.

4. MENU - GameObject -> Create Empty  (WOW!)

5. In the Project Pane click the "Create" button and drop down to "JavaScript". A script name will appear.

6. Drag the script name onto the GameObject in the Hierarchy pane. This associates the Game Object with the script.

7. Open up the script i.e double click it. And enter the following....

function OnGUI () {
    // Make a background box
    GUI.Box (Rect (10,10,100,40), "Hello World!");
}

8.Best to save things now... MENU - FILE -> SAVE SCENE AS    then call your scene something like "helloScene1"

9. Double click your Scene in the Project pane to make sure it is selected.

10. Click the PLAY Arrow at the top of the screen.

The text HELLO WORLD with a blue box should appear! Bloody hell we're done it!

Ok so how big is this basic file going to be if we deploy it to web? My first guess was several hundred K as I expected lots of unused assets and functionality of Unity to be included in the build. Let's find out....

11. MENU - File-> Build Settings - click add current which will put your "helloScene1" scene into the build list

12. Click BUILD and select a place to put the output files. Once done goto the files and open the WebPlayer folder and double click the WebPlayer.html file. Your new creation can be seen in the Browser!

The GOOD NEWS! The UNITY file is only 43K! HURRAH!

That will do for today :-) Tomorrow we can analyse what we have done and work out what GameObject, Scenes and Scripts are all about.

Wednesday, 9 February 2011

Day 2 - Learning from Books = waste of money?

In the past the first thing I have done when learning a new language, development process or application is log onto Amazon and buy the best rated book I can find on the subject.

Suffice to say I have invested many hundreds of pounds in my library of books. However I would estimated that only about 20% of the books I have bought have been a worthwhile purchase.

So this time with Unity 3d I am NOT going to spunk waste my hard earned cash . I'm sure there are some great books out there - in fact I considered buying the following 2 books - so if you like to have a hard copy book by your side, whilst you learn, they I'd go for one of these....

1.Unity 3D Game Development by Example Beginner's Guide by R Creighton

2.Unity Game Development Essentials by W Goldstone

Both books get good reviews. It appears that the 2nd book by W Goldstone will be updated around April 2011 so it may be worth waiting for that. You can read samples of both books on the Packt publishing website. Decide for yourself!

Click here for the website - www.packtpub.com

So, being the tight-fisted so-and-so that I am we will be learning Unity 3d on the cheap. i.e from the web. There are many tutorial and blog sites out there and also Unity appears to provide decent tutorials and language references etc. Time will tell.

Rememember I know as much as you about Unity 3d i.e fck all not very much.

The next lesson we will actually fire Unity up and see what all the fuss is about!

New to Unity 3d - Day 1

I am a Flash web games developer based in the UK. For a few months now I have been aware of new technologies and new platforms in the casual games market.

Having dabbled with various new languages and packages I have decided to give Unity 3d a go. It's ability to export to web, iPhone and PC/Mac (amongst many others!) has swayed my decision to look at as a medium to long term alernative to Flash for my development.

Over the coming few days, weeks and maybe months I will share my experiences programming Unity 3d, and document my progress in evaluating its strengths and weaknesses in the games development market.

If, like me, you are a complete novice to Unity 3d but have some games programming knowledge then please follow me and hopefully we can learn plenty as we go along.

First you need to download Unity 3d.  The good news is it is FREE (well the basic version is). The bad news - if like me, you are on a shockingly bad internet connection, is that it is 420Mb - it took me about 8 hours to download but I'm sure many of you with your new fanglesd mega-broadband can download this in a matter of minutes.

Download Version 3.1.0 here.....

http://unity3d.com/unity/download/

Once you've done that come back and we'll get started. Don't forget I know nothing about Unity 3d so we can learn as we go! HOLY FCK!