With the code below I am able to get positions around a circle but I have to give a certain degree for quantization (I lack a better word to describe it, since English isn’t my first language), what I want to achieve is to automatically calculate the distance between objects and make the object density in the circle related to the distance to the origin.
if (Physics.Raycast(ray, out RaycastHit raycastHit, float.MaxValue, layerMask))
{
var radius = 5;
var quantization = 15; // I want to calculate this variable automatically
float angleRadian = Mathf.Atan2(raycastHit.point.x, raycastHit.point.z);
float distanceFromOrigin = Vector3.Distance(Vector3.zero, new Vector3(raycastHit.point.x, 0, raycastHit.point.z));
var degree = angleRadian * Mathf.Rad2Deg;
degree = Mathf.Floor(degree / quantization) * quantization;
angleRadian = degree * Mathf.Deg2Rad;
truePos.x = Mathf.Sin(angleRadian) * radius;
truePos.y = 0;
truePos.z = Mathf.Cos(angleRadian) * radius;
structure.transform.position = truePos;
var dir = truePos - Vector3.zero;
dir = Vector3.Normalize(dir);
structure.transform.rotation = Quaternion.LookRotation(dir);
}
So I could create circular layers with objects like below:
