# Rotating objects in an random rotation around center point

I almost have what I'm looking for. Still trying to understand rotation and spawning of objects.

I have a ground field with a number of spawn points (and they are placed randomly in a circle). It's working quite well.

I have the issue tho, that I'm spawning them in an angle I'm not intending to and I have troubles finding the issue and understanding the math to it.

This is what it looks like: I want the rocks to be spawned around the circle on the ground, not 90° to it.

I have the following code:

Vector3 RandomCircle(Vector3 center, float diameter) {
float r = diameter / 2;
float ang = Random.value * 360;
Vector3 pos;
pos.y = center.y + r * Mathf.Sin(ang * Mathf.Deg2Rad);
pos.x = center.x + r * Mathf.Cos(ang * Mathf.Deg2Rad);
pos.z = center.z;
return pos;
}

• Did you mean to swap y & z here? – DMGregory Apr 16 '19 at 16:10

## 1 Answer

Thanks again to @DMGregory, the answer as quite simple. I made an mistake and needed to include Y and Z.

with this I was able to get my wished result.

pos.z = center.y + r * Mathf.Sin(ang * Mathf.Deg2Rad);
pos.x = center.x + r * Mathf.Cos(ang * Mathf.Deg2Rad);
pos.y = center.z; • Don't forget to mark this answer as Accepted if it solved your problem. – DMGregory May 6 at 10:58