Unity

Miscellaneous Forums/General Discussion/Unity

Some people were wondering how I was getting on with Unity :)

So, I present a very simple craft movement (with gravity) program :

(Mac - Universal) - http://homepages.nildram.co.uk/~nichkk/MiscThings/Unity%20Demo%20Mac.zip
(Windows) - http://homepages.nildram.co.uk/~nichkk/MiscThings/Unity%20Demo%20Windows.zip

Its loosely based on the control system for Zarch.

Fire button to thrust and mouse to tilt and bank.

It took me ages to try and work out how to move the craft 90 degrees to it current angle - and then I found what I wanted already built in :)

The Windows version doesn't look as good as the Mac one, for some reason (craft is just black and no animated sea), but it does work.

Why don't you publish a USB for OSX, so that people with a PPC also could have a look at? Or make it a webplayer?

I'll make it Universal now...

One thing that is annoying, is that rotation is accumative and not absolute - makes resetting angles a bit of a problem.

Just had a quick look at it: I had problems steering the ship as i had to roll x-times over the mousepad just to rotate it a few degrees.

The rotation speed hasn't been decided yet - at the moment its rather slow, so will need changing.

For those interested, the only code present is this (to control the craft ) :

var turnSpeed=40.0;
var thrust=0.0;

function Start()
{
	thrust=0.0;
	transform.Translate(0.0,0.0,0.0);
}

function FixedUpdate()
{
var bank=0.0;
var tilt=0.0;
	
	bank=Input.GetAxis("Mouse Y")*Time.deltaTime*turnSpeed*-1.0; 
	tilt=Input.GetAxis("Mouse X")*Time.deltaTime*turnSpeed*-1.0;	
	
	if (Input.GetButton("Fire1"))
	{
		thrust+=Time.deltaTime*25.0;
		if (thrust>5.0)
		{
			//thrust=5.0;
		}
	}
	else
	{
		thrust-=Time.deltaTime*25.0;
		if (thrust<0.0)
		{
			thrust=0.0;
		}
	}

	transform.Rotate(bank,0.0,tilt);
	rigidbody.AddForce(thrust*transform.up);
}


All the animation and physics is handled by Unity, and not by me.

Normally you only need DeltaTiming if you're in an Update() event not in FixedUpdate(). Try to place only physics related stuff into FixedUpdate() as otherwise this will eat up performance depending on the FixedTimeStep you've defined.

Okay - moved non physics stuff into Update()