Sunday 26 January 2014

Uploaded a video of the demo for inStasis at its current build. Verry glitchy and rough. Im still working on aspects of it before I upload another playable build.

http://youtu.be/9z4btRzdflk
Just to let you all know. I am extremely frustrated that I cant do anything more than what I'm doing now. But there isn't much to do till i can fix my PC.

LODs and Misc scripts

So I've been having alot of problems with my pc lately. I'm going to have to drop $700 onto it AGAIN before I can continue to make games or anything. That and I've been having a lot of trouble signing into my blogger account for some reason...

In any case. I've started thinking about doing a quick video tutorial on how to set up a basic game and some simple scripting and stuff. Some people have asked for it, and I would like the opportunity to teach myself some things from doing it, so I figure why not.

I've been working purely on concepts, scripting and small game dev work (due to the pc problems I'm constantly stuck in those phases, any thing more and my pc just restarts)

So I've decided to post a couple scripts I cooked up in 5 min to handle anything I need.

The first one is a script that makes an object look at the another object. This is useful to make an arrow point to an object to form a way point. Or to make a gun aim at a target. Or to make a directional light look at the player in space to simulate a sun. Or even to make AI face the player.

C# LookAtObject script

using UnityEngine;
using System.Collections;

public class LookAtObject : MonoBehaviour
{
public GameObject LookingObject;
public GameObject LookingTarget;

// Use this for initialization
void Start ()
{
LookingObject.transform.LookAt(LookingTarget.transform);
}

// Update is called once per frame
void Update ()
{
if (LookingTarget != null)
{
LookingObject.transform.LookAt(LookingTarget.transform);
}
}
}

The second script is here is a simple script to handle LODs and things like that. Its a little more tweak able and editable than Unitys built in LODs and can be used for a vast variety of things. You can use it to make AI behavior change over a distance. Or disable a lens flare or shadow casting light past a distance. Or swap objects for different qualities for better performance. Or do some tripy set pieces.

C# LODs script

using UnityEngine;
using System.Collections;

// An important thing to note with this script is that the objects are all still stored in memory, but ONLY the activated LOD object is rendered, lit and checked for physics. So while this script will increase performance, its still not perfect untill it removes objects completely upion lods.
// Someday I might write code that does more than just activating and deactivating objects. Like instansiating, cloning and destroying like you would a gun shot, but for now, this is what I need at this time.

// !**INSTRUCTIONS**! ----- So. What you want to do is these easy steps:
// 1) Make 5 LODs of an object (I recomend mudbox for this) !!!!! - remember that if you are using an object that will 'pop out' completely, the lowest quality model will be an empty game object. !!!!! - If you want to use less than 5 objects, simply set the unused objects as thesame lowest quality asset or just tweek my script.
// 2) Create an empty game object in Unity.
// 3) Put your various quality models inside the empty game object and make sure they are aligned (So that when they are enabled or disabled the object is always in the same position) !!!!! - note that naming is not important.
// 4) Attach this script to the empty game object that houses all the child LOD objects.
// 5) Drag each LOD object from the empty game object into its respective slot in the script properties.
// 6) set your desired distances between the player camera and lod levels.
// THATS ALL.

public class LODs : MonoBehaviour
{
public GameObject PlayerCamera;
public GameObject LODprefab; // the empty game object holding your LODs

// Arange models from -|/Highest quality (0)\|- to the -|/lowest quality (4)\|-
public GameObject LOD0;
public GameObject LOD1;
public GameObject LOD2;
public GameObject LOD3;
public GameObject LOD4;

public float LODdistance0; // LOD0 is active from 0 up to this distance
public float LODdistance1; // LOD1 is active after LODdistance0 and up to this distance
public float LODdistance2; // LOD2 is active after LODdistance1 and up to this distance
public float LODdistance3; // LOD3 is active after LODdistance2 and up to this distance
// LOD4 is active from LODdistance3 and further

public float ActualDistance;

// Use this for initialization
void Start ()
{
ActualDistance = Vector3.Distance (PlayerCamera.transform.position, LODprefab.transform.position);
}

// Update is called once per frame
void Update ()
{
ActualDistance = Vector3.Distance (PlayerCamera.transform.position, LODprefab.transform.position);

if (ActualDistance < LODdistance0)
{
LOD0.SetActive(true);

LOD1.SetActive(false);
LOD2.SetActive(false);
LOD3.SetActive(false);
LOD4.SetActive(false);
}

if (ActualDistance > LODdistance0 && ActualDistance < LODdistance1)
{
LOD0.SetActive(false);

LOD1.SetActive(true);

LOD2.SetActive(false);
LOD3.SetActive(false);
LOD4.SetActive(false);
}

if (ActualDistance > LODdistance1 && ActualDistance < LODdistance2)
{
LOD0.SetActive(false);
LOD1.SetActive(false);

LOD2.SetActive(true);

LOD3.SetActive(false);
LOD4.SetActive(false);
}

if (ActualDistance > LODdistance2 && ActualDistance < LODdistance3)
{
LOD0.SetActive(false);
LOD1.SetActive(false);
LOD2.SetActive(false);

LOD3.SetActive(true);

LOD4.SetActive(false);
}

if (ActualDistance >= LODdistance3)
{
LOD0.SetActive(false);
LOD1.SetActive(false);
LOD2.SetActive(false);
LOD3.SetActive(false);

LOD4.SetActive(true);
}
}
}



Hope that someone who needs these scripts finds them here.


Thursday 2 January 2014


Right. So I've been working on several new systems to implement. The most notable is a lot like easydrive from Need for Speed or Burnout. It can do anything from setting a waypoint between different locations and displaying an arrow towards it on the screen, or even for fast traveling between locations. It also displays the relevant info on the map, however it does make a map less relevant and maybe not necessary at all (I will always keep the big map, but I may remove the mini map)

I've also been testing how robust my Hover car script is and have found that it can do anything from cars to hover bikes and even space ships and jets. It means that its a useful script that I could Plug into any future project.

I've also been planning some theory behind coding so that whenever I code up a new script that will always be useful to future projects (Like a script to handle LoDs or Waypoint handlers) that I can code it in such a way that its non specific and easily implemented into any project.

I'm also working a lot in mudbox. Its an extremely robust tool and the more I use it the less I use anything else. Its workflow is easier that most other programs and I find myself creating Highres assets there and using the export function to flatly export it straight to the game, thus saving time.

I'm also transitioning to Gimp from Photoshop, purely because of the license cost but I'm pleased by the results. They are fairly similar and Gimp has an amazing built in normal mapping tool that is a life saver, especially when in need of normal that just are not there by default.

Ill post some random pictures from all of the things I've mentioned above. (SpaceShip from car script / EasyDrive setting waypoints / Gimp's Normal Mapping)

(Please note that this is just a side project that I'm using to learn and to improve my skills. I did not create the Ratchet Assets, they were ripped from the PS2 games. So all credit for those models goes to Insomniac and the Guys that ripped them off the disks.)