0
\$\begingroup\$

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:

enter image description here

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;
}
\$\endgroup\$
  • \$\begingroup\$ Did you mean to swap y & z here? \$\endgroup\$ – DMGregory Apr 16 '19 at 16:10
0
\$\begingroup\$

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;

enter image description here

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.