Game Dev Tech Notes =

Tools, Tricks + Assets


C# Unity Notes

Be aware that Unity calls Awake() and Start(). Awake() is where initialization is done first and once. It is the best place to initialize your member variables. Try not to use constructors as you would in non-Unity applications. You may develop a init() method paradigm with parameters that you can use as your own convention.

Use prefabs and nest (aka parent) meshes which have animations. This means that you should minimally create an Empty Object and then put your model Object as its child. Parenting will keep the animations from being positioned in absolute coordinates, and you can move the parent (could be an empty object) and then the child will animate in relation to the new parent.

For beginners, remember that every object has a transform components. Unity has a strong composition paradigm, in that every object extends its capabilities by adding components to the object.

If you do a lot of parenting you need to be aware that you often will want your children objects to keep a nil transform (not a hard rule by any means), but typically this is what you want. If you get strange results when transforming a parent take a quick look at the children object's transforms. Are they zero, or at least what you expect?

When instantiating an object, be aware that you will want a member variable to hold the return value if you plan on doing anything with the new object in code in other methods.

Finally, know of the myriad ways to do transforms, including localPosition, localRotation, etc. You will often find multiple ways of doing the same thing and functions to switch from local to world and back. Use the quaternions. You don't need to be a math major to use them.

Feel free to contact me, Mike Croswell, if I can help you get started. The unity reference materials, combined with experimentation is a great way to learn (remember to turn on the C# view of the script examples!)

C++ Notes

As a CS Instructor, I should just tell you about a great site: http://www.cplusplus.com/ if you are looking for incredible online help in C++. If you need a text book with lots of examples I can recommend two great text books (Deitel and Deitel and Malik). Finally, as you recall, in text-based games we often use the cin object with the get() method
cin.get();
. While this is a good way to pause the program it does require the user to press the return key. For a smoother user-experience check out _getch(). You can use it to read from the keyboard with or without echo. Good for reading arrow keys (takes two reads - one used a filter )! Another good game function is rand() and srand(). Use modula with rand() and make a macro or function to do different ranges and distributions (two random variables can create a bell curve for example).

Another tidbit is that if you are writing template code, some compilers have troubles with templates, and so if all is fails, put the implementation in the include file (usually reserved for just declarations of course!) and use the inline keyword as needed.

Script Notes

If you are a programmer that is used to strongly typed languages (C++, Java, etc.) you may find that the supposedly easier script programming is actually quite challenging at times. To save yourself, from yourself, I suggest using the strict pragma which will force you to declare the type of all your variables. Additionally, work on very small pieces at a time. Then test them and even step through using something like Torsion (for Torque 3D/T3D), MonoDevelop (for Unity), Flash Pro (for ActionScript) etc. I work on much smaller bits when scripting, since, at least for me, I can make many mistakes which will not be caught during compilation. Of course, as the IDE's get better, and enforcing typing in the particular script language, many of these problems are lessened. For example, Unity can use MonoDevelop (on Mac) or Visual Studio (on PC) to debug scripting. Still, for the scripting student that comes from a traditional programming background these following notes (taken from my own commented code - most T3D cs) are for you:

Things to look for when things don't make sense when programming in and Script. (maybe the first two just relate to me, but I'll share):

  1. Get you mind in top shape, means the mind's temple should be in good shape too: Health = Exercise + Rest/Play + Water + Food
  2. T3D: Put the % in front of the variable (for locals) and the $ in front of variables (for globals). You may make the mistake of putting these at the end of the variable, especially if you have been a Visual Basic programmer, you may be sorely tempted to put them after (ints and strings in earlier VB used % and $ respectively)
  3. For C/C++ programmers you need to remember that script language may do multiple dimensioned arrays using a different syntax. For example, in C++ you use myMatrix[m][n] but in T3D it's myMatrix[m,n] (there are other formats to represent the same thing - but you will prefer this one.)
  4. In JavaScript and Unity Script: Remember to add the keyword "function" in front of class::method's (unlike C++ or Java there is no return type) so, think...
    function MyClass::myMethod(%typeless_params, ...)
     {
     }
     
  5. T3D: Remember to exec() any new modules you write. Otherwise you may just keep wondering why the function is never called. Once again, unlike C++, the compiler will never complain. Also, order may be important to you in the usage of the exec() but please read below about onAdd() and onLevelLoaded() if this is the case.
  6. T3D: Use MyClass::onAdd(%this) and don't forget to access super class via Parent::onAdd(%this) where unlike other object calls, the %this must be explicitly passed. Of course, the super class will need it's block of code as MySuperClass::onAdd(%this).
  7. T3D: Don't assume all objects that you may need access to are constructed (exist) during your particular usage of OnAdd(). I you need access to other objects, remember the order of datablock and object construction (new'd) and use onLevelLoaded(), where (at least in TGB 1.7.4) each object gets this message after the level is loaded and most init's have been called.
  8. ...

Progress on Park Planet Nine (PP9)

I am re-making this in Unity. My MacBook couldn't run Torque Pro, so I switched!

Old T3D Notes: I finally was able to get a decent tunnel built as an interior using Torque's Constructor, slice and finally exported as a Torque dif.

I've annotated the problems I still need to solve.

  1. A "brush" has disappeared.
  2. A "leak" problem.
  3. Texture needs to map better. Smoothing would make the crease disappear.

Last updated: February 27th, 2011