One Script / Random Rotation / Multiple Objects

[newbie - 1 day of experience]

I have 9 cubes on screen (grid 3x3).

I want to keep rotating them in different directions at different speeds.

I made a single script and assigned it to all 9 cubes.

`void Update ()

transform.Rotate(Random.value / 4.0f, Random.value / 4.0f, Random.value / 4.0f);

But all the cubes spin in the same direction? My guess is the problem might be single evaluation of the script??

Any thoughts/solutions?

You are on the right track but forgot a couple of things. Your algorithm will actually vary the rotation as each cube will show discrepancy in rotation over time. The problem is that they will always move in the positive direction along the x,y,z axes because Random.value is a value generated between 0.0 - 1.0

This is how you get both positive and negative rotations, as well as greater randomness in axes:

private var x = Random.value - 0.5;
private var y = Random.value - 0.5;
private var z = Random.value - 0.5;

function Update()
    transform.Rotate(x, y, z);

Simply set the x,y,z in the Update() loop if you want a jittery effect instead.

You can also simply do this:

transform.rotation = Random.rotation;

But I doubt you'll want to change that every frame as it'll be hyper. It is good to use in the Start() function to set an initial random object rotation.