wondering how to use random.Range , to switch the facing of an object between z+ or - and x+ or - . i know that i will also have to use Vector3. i know i will also have to use addtorque as the object i want to apply this translation to is a rigid body. so any input you guys could give me would be amazing, as i just cant get my head around this, thank you in advance!
The context in which i wish to use this script , is a cube primitive, which if clicked, will randomly face a different direction . it already has a force applied in the forward axis (z+)
If you want it to just be directly along one of the axes, you’d pick a random number (from four) and use that to determine which direction:
var dir : int = Random.Range(0,4);
var tx : Transform = cube.transform;
switch( dir ) {
case 0: tx.forward = Vector3.right; break;
case 1: tx.forward =-Vector3.right; break;
case 2: tx.forward = Vector3.forward; break;
case 3: tx.forward =-Vector3.forward; break;
}
If you want any facing at all along the X/Z plane:
var newDir : Vector3 = Random.insideUnitSphere;
newDir.y = 0;
cube.transform.forward = newDir;
this ended up working perfectly, cheers