Hi Guys, hopefully a very easy to answer question - until now I have always used Random.Range like here:

rb.rotation = Random.Range(0, 360f);

Now, I want to spawn the object with four different fix rotations (facing up, down, right, left). I can’t find the correct command for this, can you help?

Thanks

Pick a random integer 0 to 3 and multiply the result by 90:

```
int randomStep = Random.Range(0, 4);
float angle = randomStep * 90f;
rb.rotation = angle;
```

2 Likes

A more generalized solution might be to query into an array of valid rotations:

```
float[] possibilities = new [] { 0, 90, 180, 270 };
int randomStep = Random.Range( 0, possibilities.Length );
rb.rotation = possibilities[ randomStep ];
```

2 Likes