Hey community.
My game is a 2D perspective along the global Z axis so Y is up and X is left and right. Right now I am trying to instantiate a set of quads in a circle. I essentialy want it so the quads rotate along their Z axis to point their Y axis at the center of the circle.
Here are a couple of images of my issue.
Red line is X axis, Green line is Y axis.
This first image is my current state.
And this image is what I want to achieve.
And finally here is my code I am using to create this.
for (int pointNum = 0; pointNum < numPoints; pointNum++) {
float i = (pointNum * 1.0f) / numPoints;
float angle = i * Mathf.PI * 2.0f;
float x = Mathf.Sin(angle) * radius;
float y = Mathf.Cos(angle) * radius;
Vector3 position = transform.position + new Vector3(x, y, 0);
Vector3 direction = (transform.position - position).normalized;
Quaternion rotation = Quaternion.LookRotation(direction);
rotation.x = 0.0f;
rotation.y = 0.0f;
if (objectPrefab != null)
Instantiate(objectPrefab , position, rotation);
}
Is anyone able to give me some pointers on how to achieve this?
Regards
- Matt