Friday, April 25, 2014

Adding Some Game Art To My Ludum Dare Entry

I've created some simple voxel-style textures for my cubes, which the character will be drilling through after some scripting.  The top layer is grass, and underneath there are 3 dirt (diggable) and 1 stone (non-diggable) cubes below.

Some quick voxel art

Basic Setup in Unity3D

I haven't imported NGUI yet, but I have got a pretty decent hierarchy setup in Unity already.  My concept drawing seems to be working out so far.



Time to get back to it, time is a' wastin'

* In all the LD excitement, I had saved this post as a draft rather than publishing.  If it is out of order, that is why.

Ludum Dare Has Begun!

My first Ludlum Dare started about 40 minutes ago with the theme 'Beneath the Surface'. In those forty minutes I played around with various ideas, ranging from Atlantis to spelunking to a dungeon crawler.  I wanted to keep things simple, so I considered games from my childhood that I enjoyed playing.  Dig Dug and Qbert came to mind and my idea was born.  My game for Ludum Dare will be a hybrid of these two game in which a character must navigate down the play area as deep as they can dig without getting killed by a falling rock (I may have other disasters like quick-sand and the like if time permits).

My concept drawing for this untitled mining/digging game for Ludum Dare

I'm not going to worry about names at the moment, but it's time to fire up Unity3D and get NGUI imported so I can begin work.

Tuesday, April 22, 2014

Unity3D: Getting a Camera to Follow an Object with Smoothing

For use in my current prototype, Codename: Factions, I needed a system that would allow me to pass a gameobject to a function and then the camera would pan over to center that object on the screen regardless of it's location.  I wanted the transition to be smooth, efficient, and useful in any scenario.


My first thought was to use the gameobject I wanted to follow as the target, but before starting I could see some scoping issues arising in the future.  My solution was to create a simple cube, disable the Mesh Renderer and any other Components I didn't need, and set that as the object for the camera to follow.  To follow a character who was chopping a tree, for instance, I could simply parent the invisible cube to the character, and wallah, it appears as though the camera is following the character.  This makes things much easier to work with, since my code is as simple as "camera, follow the same object you've been following since the level loaded" rather than "hey try and follow this object, and if there's an error, try this, etc. etc."  Best to keep things simple.

Mesh Renderer for the Camera Target is disabled rather than removed, so it can be turned on at any time for debugging purposes.

With that done, next was the transition from the cameras current location to the desired location.  Again, keeping things simple, I created a container object for the camera, which allowed me to position the camera however I wanted while keeping it's container nicely located at Vector3(0, 0, 0).  Why was this important?  Well, it makes animating camera positions much easier in the long run, since while the camera moves within it's local space, the container itself will always be located in the same position as the invisible cube that it is following.  So, if you want to zoom down to the object and get an up-close-and-personal shot, it's as easy as adjusting the local transform vector of the camera itself... meanwhile it's parent's world position is still exactly where it needs to be.  Need the camera to zoom out?  Just subtract from it's current local z position.  Wallah.

A very simple camera heirarchy

Alright, so now I have a container with a nested camera and an object to follow.  If I wanted the camera to simply snap to the position I pass to the function, then I'm basically done.  But what I want is to pass a Vector3 to the function and have the camera automatically pan itself to that position.  Vector3.SmoothDamp to the rescue!

 Camera.main.transform.parent.position = Vector3.SmoothDamp (Camera.main.transform.parent.position, cameraTarget.position, ref _cameraVelocity, _cameraSmoothTime);  

If you're new to Unity, and have not played around with Smooth.Damp, or Lerping, or Slerping, I highly suggest you take the time to learn it.  It makes smooth movement between Vectors in Unity as simple as one line of code, and that's pretty much as good as you're ever going to have it.


Monday, April 21, 2014

Adding A Little GUI To The Mix

What can I say... sometimes you just have to work on what has you most inspired at the moment, and right now that's my prototype.  I've added some basic GUI elements, which will come in handy when this Orc starts harvesting the trees for lumber.  I've also got some buttons down in the corner, which will come in handy on touch devices.  Lastly, I've added some selection indicators for both the current selected object (circular) and that objects target (square).

My opinion may be biased, but this is really starting to look like a game to me

My goal is to program the Orc worker so that when he chops the tree, he gathers resources over time.  When he has chopped all he can carry, he will return it to the tower, and then go back for more.  Before I get this done I am going to convert the movement system to use Unity3D's NavMesh, rather than the temporary one I have in place.  This will allow the Orc to walk around obstacles to reach his destination, which will come in handy in the future.  I'd put this off, but I have a feeling if I programmed the resource collection system first I'd pay for it in the long wrong with a lot of re-written code.  Best to do things in order, at least when the opportunity presents itself.


Chop A Tree or Raze A Defense Tower!

Adding interactions went smoother than I had originally thought.  With some quick trigger collision detection and animation controller scripting, you can now right click and tree and the orc will begin chopping it when he arrives.  You can also click the tower and he will begin attacking it.  I will be modeling a hammer in the near future to replace the axe when this happens, so he will be building the tower rather than attacking it.
The Orc can now chop trees and attack the tower

Unfortunately the treasure chest asset does not open, or I would have added that interaction as well.  
My next step will be to begin work on tracking how much wood has been gathered, and removing the tree when it's resources are exhausted.  From there the orc will bring the resources to the blank area where the tower exists now and use the lumber to begin construction.

<< TAKE ME TO THE DEMO>>