Sunday, July 28, 2013

Ghost Train RPG - Unity 01

Ghost Train RPG - Unity

First in a series of worklogs for creating a Unity RPG.

Scene 001 is going to be our starting scene.  We are in the middle of a small town on the rails.  Here is where we'll be introduced to the world, talk to some people, gain employment and buy some stuff.

Our city should look like a Victorian era city mixed with steampunk/futuristic elements.  Cobblestone streets, old brick buildings with lots of pipes, signs, and some futuristic generator looking stuff.

Start a new scene.
Game Object/Create Other/Plane
Change scale 1000,1,1000 (might shrink that later if it's too big)
Rename it to "Ground"
Under Assets, create new folder "Ghost"
Under Ghost folder, create new folders "materials" "textures" "scripts" "prefabs"
Found a good cobblestone/brick texture at Texturelib.com
Imported into Assets (under Textures)
In Materials folder, right click, Create/Material, named Cobblestone01
Drop texture into Material for diffuse (We'll add normal in a sec).
Project Hierarchy/Standard assets/Character Controllers
Drop "First person controller" onto your scene.
Delete the game object named "Main Camera"...you'll have one attached to your Character Controller

Now sometimes it's a bit difficult to find where you put something.  Do this:
On your plane named "Ground", change Transform to 0,0,0
On your Character controller, change Transform to 0,1.3,0 (you can also just put it at 0,0,0 and drag it up on the y axis.  The character controller has to be completely above the plane, but not much otherwise he'll fall through).

Now, when I test the game, I see that the plane is grey cause it is large and the material is not tiled.  I played around and found for my material that 2000x2000 tiling looks good (it's going to depend on your texture and the size of your plane).

Now, make the normal map for your texture.  Easy way is to take your diffuse texture and make a copy of it and import into Assets.  Then in the Import Inspector, choose Texture Type=normal map.
In cobblestone01 material, select Shader=bumped diffuse.  Drop your normal map onto the normal map texture.  I want to see the bumpiness, so I add: Game Object/Create Other/Directional Light.  Right now I don't care what direction it's pointing.

Test the scene and it's crazy bumpy!  Back to our normal map in the Inspector.  Change bumpiness to 0.05 and apply.  That's good for now.  I'll prolly go in later and change it a bit...there's improvement to be made.  But it's fine for now.

BTW, Save Often!  My Unity crashes a lot!

Saturday, June 15, 2013

Jinx Minecraft Tshirt contest design

Well, I created this design for the Jinx Minecraft contest, but it was not accepted.  I think it must have been the contrast was not great enough and would not have looked clear on a shirt.  I hope that was it cause I spent a ton of time on this and thought the idea was sound.



XNA off; Unity On (and how to successfully import a Blender model into Unity...)

XNA being a "dead" language now (or at least no longer supported), I've switched to Unity.  Big change, but I'm liking it so far.  Some of the Unity Engine makes programming so easy, while the rest is just as difficult as XNA was.  The graphics is extremely fun and easy.

So, my Ghost Train project will move to Unity and likely will be 3D, just because I'm having a blast relearning Blender and putting that together with Unity.  I'm a complete noob, so even though there are thousands of tutorials out there for Blender and Unity, I'm going to post notes and examples.  There are some very specific things you can do with these two programs that make the workflow so much easier.  Maybe I can save just one person a headache trying to figure this stuff out.

Currently, I'm using:

Blender 2.67
Unity 4.1.5f1
a very old version of Photoshop (6.0.1 ...no, not even CS...I've had this one for years and years and it's comfortable)

So, here are my steps to create a model in Blender and import into Unity successfully (lots of trial and error and forum scouring to get to this point!).

  1. Well, create the model.
    1. Base mesh, extrude, rotate, scale (more on this in another post).
    2. Knife tool to cut new faces when needed.  Mesh Tools/Add/Knife.  Drag from one area to another and then hit enter to finish cut.  Seems to work best between two established edges.
  2. For each object in the model, first make sure all normals are pointing out, otherwise parts will appear missing or transparent.
    1. Select object
    2. Put into edit mode (tab)
    3. On a 3d view window, type "n".  Brings up a set of info on the right side of the view.
    4. In Mesh Display/Normals, click the face button and set a size that makes sense.  If the normal is pointing out, you will see it radiating from the center of the face (blue line coming out).  If not, it's pointing in.  If it's pointing in, select the faces pointing and do:
      1. From the bottom menu do, Mesh/Normals/Flip Normals.  Repeat this for groups of faces until all are pointing out.

  1. Now UVW Map the object(s)
    1. Go to Edit mode.
    2. Use edge editing and select edges to cut.  Then choose Mesh/Edges/Mark Seam.  This is the cut for the UVW map.
    3. Repeat until you have broken the model down into parts that make sense.  
    4. Now, select all faces, type "u" and choose Unwrap.  If you have one view as UV/Image Editor, you should see the mapping.  
    5. Export that mapping by doing UVs/Export UV Layout
    6. Paint the texture using your favorite image editor.
  2. Apply the texture to the object (Select the object, in UV/Image Editor pick Image/Open Image).
  3. Save as a blend file.
  4. Put the blend file and the text map(s) into the Assets folder of your Unity project.  It will automatically import it (even at runtime).  
  5. This step saved me a lot of headaches:  Go to the import settings of the blend model in Unity, and choose to Calculate Normals.  This makes the model look like you created it in Blender instead of trying to smooth it out and making it look terrible (at least all mine have...even a simple cube).  To me, this is key...especially when doing wall segments that snap together...otherwise the light will break up on each piece making it look like each object is separate instead of one unified wall.  I do this on all models!

Wednesday, May 1, 2013

Ghost Trains - Librarian Concept

Concept art for Librarian.  I envision a wizened older character carrying a large book or scrolls.  When he moves, papers fall out of his book behind him.


Wednesday, April 17, 2013

Ghost Train - Coding in a dead language

So, I find out today that XNA is essentially a dead language.  Microsoft will not longer support it and offer new releases.  It will be considered officially dead on April 1, 2014.  That leaves me in a bit of a conundrum.  Do I continue on in XNA, having only just started to learn it and not too deep into coding my game that it would hurt to stop?

If I do stop, then what?  Unity?  I've tried it and I know it's powerful (I've played many great games made with Unity), it just doesn't feel like coding does in XNA.  I like to see the lines of code.  That's part of the draw for me.

Likely I will continue on with this project in XNA and then figure out what's next for the next project.  I feel like a modern scholar studying Latin.  There's not really any reason to except to do it...

Wednesday, April 10, 2013

Ghost Train - Menus and Gamestates

Of course I jumped right in and started programming the action part of the game, cause really I had to get that instant gratification of seeing graphics on a screen with some input.  Having a bit of that (still much, much more to go), I need to go back and define the menus and the rest of the game.

Here are the different states of the game:

0.  Main splash screen.  Just a picture with "hit spacebar to continue".
1. Main menu.
2. Hire hunters.  This is going to be like a  bar or employment line.  You can see your available slots and build a team off of that.
3. Purchase items.  Special equipment for the team.  Buy, then give to a character.
4. Overall map.  This is where you see all of the train lines and select the one to work.  Train lines open as you get better.  Other optional idea is that instead of a map, you get a job posting screen and you select one of a few open jobs.  Either way, this state is where you select a route to work.
5. Action state.  This is the main game on the traincars.

There are probably some sub states in there like a screen before #4 and #5 that just says press start when ready.  I can always add those in later as I identify them.

Here's where my lack of programming background comes into play.  I'm not exactly sure how to create new callouts for the gamestates, so I have implemented them directly into the "update" and "draw" processes.  This seems to work fine, though is probably not the most practical method, especially if the program was large.

Right now, gamestate 0 is the main opening menu and gamestate 1 is the action part of the game.

protected override void Update(GameTime gameTime)

        {
            if (Gamestate == 0)
            {
              //Updates here...keyboard input.
                {
                    Gamestate = 1;
                }
            }
         

            if (Gamestate == 1)
            {
              //Updates here...keyboard input.
            }
            base.Update(gameTime);
        }

       protected override void Draw(GameTime gameTime)
        {
            if (Gamestate == 0)
            {
                //Draw something here.  Main Menu
            }
         
            if (Gamestate == 1)
            {
               //Draw something here.              
            } //
          }

I also saw from Microsoft's gamestate sample the use of the region marker and I'm using that to break each gamestate up so I can quickly find it.  This marker allows you to collapse code to make it easier to find.  Kind of like a bookmark.

#region gamestate0 draw
...
#endregion

Neat!  Now I have a main menu and you press spacebar to enter the next state.  Exciting stuff!

Tuesday, April 9, 2013

Ghost Train - Controls

As this is a skill based game, I want the controls to be intuitive and quick to access.  The player should not be hunting around for keys on the keyboard, but should be able to keep their eyes focused on the screen.  Thus the keys have to be grouped and used in a manner that would allow for ease of play.

There are three control groups:

1. Character select.  This is number keys 1-5, to be accessed by the fingers of the left hand.
2. Action button.  This is the spacebar to be pressed by the thumb of the left hand.
3. Move button.  This is the arrow keys to be used by the right hand.


The flow of play would work like this:  Select a character, move that character into place, then hit the action button.  Select the next character...and repeat.  The position and facing of characters is important as the ghost will be moving and attacking and most actions have a small area of effect so characters will need to be close.

I'm focused on Windows development at this moment, but keeping Xbox in mind as well as I want to see this game on XBLA at some point.  I've considered controls for the Xbox controller and map the ideas above like this (though this would need to be tested out):