Sunday, May 29, 2011

Links: Unity Tools

Level building is pretty fiddly but here are links that might make it easier:

Positioning Objects via the Unity Manual. Check out the notes on Unit and Vertex snapping.

Align Positions via the Unity Manual. An example script from Unity.

Snap to Grid by Hayden Peake: Can be useful if you're working on a grid layout and to a particular scale.

LineMup by Matthew J. Collins. Aligns and distributes even spacing between selected objects. Comes with an instructional video.

Transform Utilites by Daniel Rodríguez (Also found here): A pretty hand tool for aligning objects in a scene, it's a little more technical than the other options but makes things much easier.

Now back to scalding my eyeballs with Wow-Wow Sauce and other ritualistic activities that make up level building. A proper post is coming

Monday, May 16, 2011

Wreckless Conduct: The Scent of Failure

Some progress shots of level building toolkit + Unity Editor + beating head on keyboard looks like. Finally got some kind of mouse click system which instantiates a prefab in the scene window.

For those interested, the code looks a little like this:

 //OnScenGUI is how the Editor handles events in the scene window
function OnSceneGUI() {
    //  Handles are like Gizmos
   // Draw cube at 0,0,0 when level builder is on
    Handles.color =;
    Handles.CubeCap(0,, Quaternion.identity, 0.5);
    if(editMode) {
        if(Event.current.type == EventType.MouseDown) {
            if(Event.current.button == 0) {
                var ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
                var dist : float;
                // Cast a ray on a "fake" plane (The Plane class in Unity is a "Representation of planes")
                // If ray hits the plane (grid stand in), use the current mouse position to instantiate our prefab
                if(grid.Raycast(ray, dist)) {
                    var pos : Vector3 = ray.origin + ray.direction.normalized * dist * 0.5;
                    Debug.Log("Placed fab at: " + pos);
                   // Using EditorUtility.InstantiatePrefab does stop me from creating clones of my prefab
                  // I could still use Instantiate(gameObject, pos, Quaternion.identity) here as well
                    var currentPiece : GameObject = EditorUtility.InstantiatePrefab(target.currentFab);
                 // Seems like the line below is causing some problems
                    currentPiece.transform.position = pos;

                }//END grid Raycast
            }//END Mouse Left Click
        // Prevent deselection of object while in Edit Mode
         Selection.activeGameObject = target.transform.gameObject;

    }//END In Edit Mode

}//END OnSceneGUI

Failure is listed down below, I'm getting worried about how long this is all taking so any suggestions are most welcome.

Edit: I've sort of resolved the fragmenting of prefabs, it had to do with my invoking of particular functions. I will be working on the functionality of the level builder.

This one is a little old but it does show that I've resolved a strange problem with the math that determined where a collider positioned itself and when you resized buildings.

For funs:
Minecraft - Unity Style. Also has a playable demo.

Tuesday, May 10, 2011

Wreckless Conduct: Streets of Hell

With about 4 weeks to go, I decide to start scripting things that will help with level building. Yes, I have under-estimated the enormity of this task. Here's a look at what I've been working on.

Building scripts for prefabs:

Material randomiser:

To Do:
- City layout
- Roads
- Buildings
- Props