Friday, May 24, 2013

Unity Ray debugging



Oh, this is a cool one I just noticed that again shows me the developer of Unity knows what they were doing.

function Update () {

    var ray : Ray = camera.ScreenPointToRay (Vector3(200,200,0));
    Debug.DrawRay (ray.origin, ray.direction * 10, Color.yellow);
}


How many times have I struggled to see where a ray or vector is doing in my game and written a ton of debug code (yes I did this with XNA) to draw a line where a ray was.  Unity gives me this as a simple Debug call.    Thank you thank you thank you.

Thursday, May 23, 2013

Learning Unity


Yeah, just what I need is another technology to learn. After a few years of teaching XNA (before that Torque, before that Java, before that J2ME and somewhere in there a quick detour for Second Life/LSL)  it seems like the world is shifting around me again. I did some quick Android apps last year, but still wanted another layer above me to allow me to release on multiple platforms. Unity keeps coming up in conversation and after a few quick tutorials and calls with a good friend who already climbed the learning curve I seem to be picking it up quickly. I had to drop it again for a few months as I got busy, but found some time recently to dig in again. So far pure joy. I've found a tool that was programmed by someone who understands.

A couple of really small things have made me really appreciate the person who created Unity. Meaning it's really well designed.

This guy gets it.
http://docs.unity3d.com/Documentation/ScriptReference/Mathf.Deg2Rad.html
This guy was an intern (as was most of the DirectX/XNA code base in my opinion).
http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.mathhelper.toradians.aspx

This will cause some arguments, but why create a function/method (XNA),

float deg = MathHelper.ToRadians((float) 1.0);

and I don't know for sure that C# does create a stack frame or not for this call, but why even chance it.  I know it's only a few extra instructions and one extra push onto the stack (if that's what it does), but if I run that a lot it's bound to do a little extra processing that I might not want to have on a slower/older device. I grew up with limited memory and CPU so I still know that every instruction is still a percentage of your maximum throughput. The less you use, the more you can do. For short, every single instruction still counts.

When this most definitely doesn't have any extra over head. (there might be an offset instruction for the Mathf. part, but not a (possibly) full stack frame creation).

float deg = 1.0 * Mathf.DegToRad;

This and a couple of other small things, like the ability to create/change a model in Blender (free) and have it automatically be updated in my game is a huge bonus. I love Blender and have struggled to use it with every game engine and with unity it's automatic. That's huge.  I can use 3ds max fairly well, but that expensive license every year for the simple stuff I build just isn't affordable.

Anyway, loving Unity after a few weeks of working with it.  Have a fun little game mechanic coming along.