Subscribe to GameFromScratch on YouTube Support GameFromScratch on Patreon
22. July 2013


For a point release, this one’s pretty good.Unity42


As mentioned in the title, probably the biggest change is the addition of 3 new platforms, Windows 8 ( as in the app store ), Windows Phone 8 and Blackberry 10.  Windows Phone 8 “Pro” is available free to Unity Pro subscribers.


Probably the biggest new feature isn’t new at all.  A number of previously “pro” level features are now available free.  Nav mesh baking ( used for AI pathfinding ), realtime shadows and text based serialization of assets for integration with version control have all become free features.  Those are perhaps the most cited missing features from the “basic” version, so if you are on a budget, that’s great news.


Other big features include:

  • OpenGL ES 3.0 support
  • Perforce source control integration
  • iOS crash reporter
  • Anti-aliased RenderTextures.
  • Numerous new image effects ( Blur, Bloom, Edge Detection, etc… )
  • Stencil buffer access (pro only)
  • Shuriken particle system callback scripting interface
  • Added the Quad primitive!


Of course, this is just a highlight of the features added, you can check them all out here.  Or of course you can just go ahead and download it, as all Unity basic versions are now free.


18. July 2013

Today the Blender Foundation released Blender 2.68.  It's not a large release, epecially compared to some of the more recent ones, but it has a few modelling features I am going to absolutely love. B268





First and foremost is the change to the Bridge tool.  You can now bridge between edge loops with a different number of vertices!  This is one of those features I miss when moving from other 3D packages to Blender.  Here is the new bridge tool in effect:



This feature is exceedingly handy for connecting multiple models together, even if it might require some cleanup later.


The next new modelling feature is Vertex Connect, which can basically be thought of as a knife tool that operates between vertices.



It's a small thing, but it will make doing face cuts much cleaner, resulting in at least two less vertices per cut.



Finally, you know have the option to split faces when you dissolve vertices.



I'm not entirely sure if I will use this or not.


On the modelling side, there were a number of revisions for symmetric modelling, and a new Grid Fill tool for filling two connected edge loops.  In many ways this reminds me a ton of the early 3DS Max patch modelling plugin ( … which name I have forgotten… everyone had a copy… ).


These images are from


If you start with this:



And apply a grid fill, you end with this:



Very cool and potentially very useful, but I HATE Blenders curve tools with a passion.


On the non-modelling side of things, the Cycles renderer got a few improvements. CPU and GPU performance were improved, a mist render pass was added, hair rendering on GPU as well new nodes were added.  On the physics side, particles now respect the modifier stack and the smoke particle sample now is higher resolution.  There were improvements to motion tracking, general usability as well as 280 bug fixes!



Not an earth shattering release, but theres enough new stuff in there that certainly make your life easier.  They had me at bridge tool!


So head on over and download it now.  I offer a 100% money back guarantee!

17. July 2013


In this tutorial we are going to look at how to handle Input using Lua scripting ( we will look at C++ later ).  I assume you have read the prior tutorials, so you should have the ability to create a new project and populate it with a new entity using the crate model we made earlier.  You do not need to export it again, you can simply copy the MODEL and texture files over to the root of your newly created project.  So, do that now, create a new project, create a default scene and add the crate model to your scene.  Next add a script component to your newly created crate entity.  If you have any problems with the above instruction, please refer to prior tutorials in this series.


In this tutorial we cover:

  • Polling for keyboard input
  • Polling for mouse input
  • Creating input maps to handle input in an abstract manner


By the way, this tutorial starts by demonstrating a way you shouldn’t use!  Be sure to read the entire post before you do anything.



Handling Keyboard Input


The following script shows how to handle basic keyboard input using Lua.  I attached the script to our entity and implement it it’s OnThink callback.


function OnThink(self)
  if Input:IsKeyPressed(Vision.KEY_UP) then
  elseif Input:IsKeyPressed(Vision.KEY_DOWN) then
  elseif Input:IsKeyPressed(Vision.KEY_LEFT) then
  elseif Input:IsKeyPressed(Vision.KEY_RIGHT) then

The key is the Input object, which is an instance of VScriptInput_wrapper, which as the name suggests, wraps input functionality and makes it available in Lua.  Another thing of note is the Vision object ( well… table if I am going to use the proper terminology ) contains a number of constant defines, in this case we access the values for various key codes, such as Vision.KEY_LEFT.  In the event of an arrow key being pressed, we move our entity calling the IncPosition() function, moving along either the X or Y axis, depending on which key is pressed.


The key thing to realize about the IsKeyPressed function is it will report true every time a key is hit.  Therefore with the above code, if you hold down the key it will fire every time OnThink() is called.  What do you do if you want to only respond when the key is pressed the first time?  In that case you use SetKeyOnHit, like so:



function OnCreate(self)

function OnThink(self)
  if Input:IsKeyPressed(Vision.KEY_UP) then


Using the above code, with the added call SetKeyAsSingleHit changes it so IsKeyPressed for KEY_UP will only return true when the UP arrow is initially pressed, and wont return true again until the key is released and pressed again.  You can toggle this behaviour off by calling SetKeyAsSingleHit again but passing false instead.



One very important point!


When testing input code, it is very important that you run your game in “Play the Game” mode, otherwise vForge will still capture and handle all the input events.  You run in Play The Game mode by clicking the down arrow next to the play icon and selecting Play The Game:



When you are done testing your game, hit the ESC key.


Handling Mouse Input


Now let’s quickly look at how you handle mouse events.  I created a new scene in the same project, added the create model and once again attached a Lua script component to it.  The Vision engine has the ability to poll the mouse for activity, which is exactly what we are about to demonstrate.


-- new script file

function OnThink(self)
	local mouseX,mouseY = Input:GetMousePosition()
  local mouseDeltaX,mouseDeltaY = Input:GetMouseDelta()
  local mouseWheelDelta = Input:GetMouseWheelDelta()
  local isLeftButtonDown = Input:IsMouseButtonPressed(Vision.BUTTON_LEFT)
  local isRightButtonDown = Input:IsMouseButtonPressed(Vision.BUTTON_RIGHT)
  local outString = "Mouse Position:" .. mouseX .. "," .. mouseY .. 
                  " Mouse Delta:" .. mouseDeltaX .. "," .. mouseDeltaY .. " Mouse Wheel Delta:" .. mouseWheelDelta

  if isLeftButtonDown then 
    outString = outString .. " Left Button Down"

  if isRightButtonDown then 
    outString = outString .. " Right Button Down"


The code is quite straight forward.  Each frame in OnThink() we poll the location of the mouse using GetMousePosition(), the amount the mouse has moved since the prior frame using GetMouseDelta(), the amount the mouse wheel has moved using GetMouseWheelDelta() and finally check to see if either mouse button is pressed using IsMouseButtonPressed().  Once again, the mouse button constants are defined in Vision.


If you run this code you will see:




Once again, like the keyboard demonstration, you need to run in Play The Game mode for Engine View to receive the input.


Creating Input Maps


Now that we’ve covered how to directly poll the mouse and keyboard for input, we will now look at handling input using a InputMap instead.  Using an input map allows you to put a layer of abstraction between you and the input devices, allowing you to map multiple control schemes to a single action.  Let’s jump right in and take a look.  I am once again creating a new scene, adding the crate model and applying a script to it.


-- Inputmap demo

function OnAfterSceneLoaded(self) = Input:CreateMap("crateInputMap")"Up", "KEYBOARD", "CT_KB_SPACE")"Up", "MOUSE", "CT_MOUSE_RIGHT_BUTTON")"Up", {0,0,100,100}, "CT_TOUCH_ANY", {once=true})

  -- arrow keys mapping for left/right"MoveX", "KEYBOARD", "CT_KB_LEFT", "CT_KB_RIGHT")
  -- WASD mapping for left/right"MoveX", "KEYBOARD", "CT_KB_A", "CT_KB_D")
  -- gamepad mapping for left/right"MoveX", "PAD1", "CT_PAD_RIGHT_THUMB_STICK_LEFT", "CT_PAD_RIGHT_THUMB_STICK_RIGHT")

function OnThink(self)
	if"Up") == 1 then

  if"MoveX") < 0 then
  elseif"MoveX") > 0 then


This time we are creating a map to handle input using the function Input:CreateMap().  If you create another map using the same name, the previous map will be destroyed.  Once we have a map, it’s a matter of defining triggers.  Essentially this means we are giving a string key and mapping it to an input event.  For example MapTrigger(“Up”,”KEYBOARD”,”CT_KB_SPACE”) is saying when the spacebar is pressed on the keyboard, trigger the trigger named “Up”.  As you can see, you can map multiple devices/keys to the same trigger.  In this example, we mapped the SpaceBar, Right Mouse Button and touching the screen in between the coordinates (0,0) and (100,100) all to the trigger “Up”.  So now instead of handling all the different control schemes in code, we can simple deal with “Up”.  If you look at the  CT_TOUCH_ANY trigger ( which we will cover in more detail later ), you can pass in a table of optional parameters in as well, in this case we are saying we want the event to only fire once per touch.


Sometimes however you want to bind an axis to an event, such as pressing left or right arrow keys, or using the thumbstick on a gamepad.  In that case you can use MapTriggerAxis().  In this case you pass in the name of the trigger, the device to use, then the values representing the negative and positive ranges of the axis.  In the first example, we are mapping the LEFT and RIGHT arrow keys to the X axis, with CT_KB_LEFT representing the negative value and CT_KB_RIGHT representing the positive value.  We also bound the A and D keys from a traditional WASD layout to the X axis, as well as the right thumbstick on a gamepad, if present.  The code will warn you that a given device isn’t present, but will run anyway.


Now in on think you can see handling triggers is extremely simple, you simply call your map’s GetTrigger method, passing in the name of the trigger you created.  Therefore if any of the triggers we defined are true ( RMB pressed, Spacebar hit or certain region of the screen is touched ), it will return 1 get you check the “Up” trigger.  Dealing with axis is virtually identical, except it returns a value from –1 to 1, depending on direction pressed.  Using a map allows you to easily handle multiple control schemes using a single code base.


In this tutorial, we looked mostly at traditional desktop controls… not really much use in mobile development.  In the next part however, we are going to look at work with mobile input.


15. July 2013


In the previous tutorial we looked at how to export a model from 3DS Max to vForge.  This time, we are going to look at exporting a mesh, then explore the difference between entities and static meshes.  As the title might suggest, components play a big part of the difference!


So in this tutorial we will cover:

  • Exporting a VMESH file from Max
  • Coordinate difference between systems
  • Creating a static mesh in vForge
  • Differences between Entities and Static Mesh Instances and when to use which



Exporting a VMESH file



First off, let’s look at how you export a VMESH file from 3D Studio Max.  We will be using the crate model we created earlier, but you can use whatever object you want.  Load it in 3ds Max and then select File->Export.




Once again I am saving the file in the root of our project ( MyFirstObject, see prior tutorial ) directory.  Make sure you set “Save as type” to VMESH then click Save.



Next you will be presented with a series of options:



I’ve highlighted two of the most important settings for you to be aware of.  First is scaling multiplier and this is pretty important.  The value of  1-unit can be defined in most modelling applications.  In vForge however, 1 == 1cm.  So if you’ve modelled your crate as 2x2x2, that means 2cm x 2cm x 2cm, also known as really really really tiny.  To make things even more confusing, in Havok Physics 1= 1 meter!   Therefore when exporting, we are scaling our dimensions by a factor of 100, so our 2x2x2 cube created in Max, with become a 2m x 2m x 2m cube when viewed in vForge.  Of course, you could always set up 3ds to work in cm’s if you wanted.  Finally, take note of the directory textures are being exported to.


Once ready, click OK.


Your newly exported model will be shown in the model viewer.  You can navigate using the WASD keys and look around using the mouse.  Chances are the camera will be extremely zoomed in when it loads.




Press ESC to close the viewer.  If you dont want it to show up in the viewer, simply uncheck Preview after Export.  Having an option to quickly see how your object will look in engine can be incredibly advantageous, but it can also get annoying.


Creating a Static Mesh Instance



You now have a VMESH file to work with, lets create one in our scene.  In your project, drag a Static Mesh Instance onto the Engine View:



Now go to the properties and locate MeshFileName:




Select our newly created Mesh object:




So, now your scene should have an entity and static mesh in it, assuming you are working from the previous project that is, like so:



But there might be a bit of an issue in your scene…




See, when exporting our static mesh, we applied a conversion from cm to m, while when we exported our model we didn’t.  This can be easily rectified in vForge however.  With your entity crate selected, go to properties and locate Scaling and set Uniform Scaling to 100:








… that’s more like it!


So, now we have two crates, one is a MODEL attached to an entity, while the other is a vMESH attached to a static mesh.  So, what’s the difference?  Good question!


Meshes vs Models, what’s the difference?


In a word, weight.  This has nothing to do with mass either.  A static mesh is a much more computationally light weight object than a model.  A static mesh is basically just displayed in the scene.  Physics can respond to it ( so for example, you can run into it ), but it does not respond to physics… it is exactly what it’s name suggests… static.  It doesn’t move, it isn’t animated, it simply is there and you can run into it… that’s about it.  On the bright side, a static mesh takes a great deal less processing power to deal with and because it is static, there are a number of optimizations the engine can perform.


A model on the other hand is a great deal more complex than a vmesh.  A model can contain a great deal more information, including of course animations.  An entity is also a great deal more capable than a static mesh instance.  Plus of course there’s components… we will come to that in a moment.  Components are a huge difference though!


So, when do you use which?   If it is part of the world and doesn’t move or require an additional component, use a static mesh.  Otherwise use a model.  For the sake of performance, prefer a static mesh whenever you get the chance.





Components are where a great deal of Project Anarchy’s functionality lies and the difference in options between a static mesh and an entity is pretty severe, see:


Components available to a static mesh:



Components available to an entity:



So, if you want to hook your 3D object up for more advanced physics, as a character controller, to Havok Behavior, etc…  you need to go with an Entity.


There is one final mildly confusing point, that you can completely disregard for now if you want.  Up until now I have used the terms VMesh –> Static Mesh Instance and MODEL –> Entity.  It is however possibly for an Entity to reference a static mesh, but not the reverse.  Again, if that is confusing… forgetaboutit!


From the code side of things, a static mesh is actually a VStaticMeshInstance_cl, while an entity is VisBaseEntity_cl.  As you can see from their prospective inheritance diagrams, VStaticMeshInstance is “simpler”.


VStaticMeshInstance_cl Inheritance diagram:



VisBaseEntity_cl inheritance diagram:



It’s the inheritance from VisObject3D_cl that is absolutely critical.  That class itself contains the functions critical to movement such as GetPosition(), IncOrientation() etc…  basically the code you need to position and move an object in 3D space.  It is also what enables the more advanced parenting options and linking available to an Entity and other VisObject3D_cl derived classes.



TL;DR version… got a 3D object that doesn’t move and doesn’t change?  You probably want to export it as a VMESH and make it a Static Mesh Instance.  Otherwise, you probably want to export it as a MODEL and implement it as an entity. 


11. July 2013


Even though Project Anarchy ships with a ton of assets, you are eventually going to want to add your own.  In this tutorial we are going to do exactly that, by creating the Hello World of game modelling… a textured crate.


Ain’t she a beauty?




For this tutorial I am using the 30 day trial of 3D Max 2014, which you can download for free right here. Of course you can use any of the supported modelling programs if you already own one.  This tutorial will not be teaching you how to model in any way, besides I suppose how to create a cube, which isn’t really all that exciting is it?  In addition to Max 2014, the prior 4 versions are also supported, as well as multiple revisions of Maya and Softimage.  Oddly, there is a plugin for Softimage, but no documentation… I’m not entirely certain of why.


In this tutorial we will cover:

  • installing the Project Anarchy content tools
  • creating and texturing a 3d crate in 3D Studio Max 2014
  • exporting a model from 3D Studio Max to vForge
  • attaching a model to an entity in vForge



Setup and Configuration



To continue if you haven’t already, install the 30 day trial of 3D Max 2014.  Then run the Project Anarchy download manager again.  Don’t worry, it will have locally cached all the install files if you ran it earlier.  You want either the 32 or 64bit version of the Havok Content Tools, depending what version your 3D app is.  In my case it’s 64bit I need.  Select the one you need and click Download.  If you’ve already downloaded everything, skip this step and jump ahead.




If you already downloaded everything, you can locate the installer in a sub-directory of your USER directory, in my case it was C:\Users\Mike\AnarchyPackages, like so:




The downloader should run the installer automatically, but otherwise you can run the one you need from this folder, select either the 32 or 64bit version of HavokContentTools and run it.  Make sure that your 3D application and Havok are closed ( just in case ).


The installer should automatically determine which versions you have installed:





If you don’t already have a vForge project and scene configured, do so now.  If you have no idea how, please refer to this earlier tutorial.  I created a project using these settings:




Strangely, it didn’t make a textures folder.  That’s it for the Havok stuff for now, let’s switch over to 3DS Max and create a simple textured crate.


Oh yeah, the texture, I am using this one:



It’s a 512x512 texture I downloaded from the web… I did not create it, nor do I have any rights to it, so do not use in a commercial project!  Now download this file and save in the root of your newly created project.  ( C:\temp\MyFirstObject in my case ) as crate.jpg.


Creating a textured crate in 3DS Max 2014



If you’ve ever used 3D Max, just skip this part completely, its 101 stuff. 

Once the installer finishes, the required plugins should now be installed.  Fire up 3D Max 2014 ( or whatever app you are using ).  In the Create Panel, left click Box icon.  Now left click and drag to draw the rectangle you want in any viewport, then release the button.  Now the next mouse movement will represent the depth of the object you are creating.  Click when done and you should now have a 3D cube.




Press ‘Q’ to switch to selection mode and make sure that the cube is selected.


Now we want to texture it… first we need to turn texture display on so we can tell if our texture is working or not.

In the Perspective window, left click the word “Realistic” and set Materials to Shaded Materials with Maps.



Now the cube in this display will display your texture once assigned.


Now lets assign a texture.  Press ‘M’ to bring up the Slate Material Editor.  From the left hand panel, drag over a Standard material and a Bitmap map.



For the bitmap, you will be prompted for the texture to use.  Select the crate.jpg at the root of your project.



Now drag the connector on the right of the Bitmap to the Diffuse Color on the material.



This assigns the bitmap texture to the diffuse channel of the material.  Now drag the connector from the right side of the material to the cube in your scene.




You should now have a fully textured cube for exporting.  If it doesn’t appear to be textured, make sure the the viewport is set to show texture maps.



Now save your scene.  For the sake of ease, I am going to save to C:\temp\MyFirstObject\Crate.max.


Exporting to vForge


Assuming you have installed the Content Tools properly, you should have a menu in 3DS Max, Havok Content Tools



Select Havok Content Tools->Export:



The following dialog will appear:



You may notice some error text about unloadable DLLs, this has no effect on the export process, you can read more about it here.


In the left hand side, highlight Process Vision Data, then on the right hand side, click Add >>



---------------------------------!!Now make sure you have your project open in vForge before continuing!! --------------------------------------------------


With your project open in vForge, click Run Configuration.



If everything goes according to plan, your model will appear in vModelViewer:



Now if you take a look at your project directory, you will see your newly exported .model ( and .anim ) files:



Congratulations!  You just exported your first 3D model from 3D Studios Max to Project Anarchy!


Using the crate model in game


Now let’s make sure it worked.


In vForge, drag an Entity from the Shape Creators panel to the Engine View:



With your newly created entity selected, in the Properties panel locate Model File:



When you click the … button, you should now be able to select your crate model.



Select it and click OK.


And voila!  Your crate model in the game engine!




We will be making heavy use of our newly created um… crate in upcoming tutorials, so stay tuned.


AppGameKit Studio

See More Tutorials on!

Month List