
As shown in the picture above, I instantiate the same object multiple times each at a random position around the circle. I just can’t get the objects to always be facing the center of the circle. Iv’e tried Quaternion.LookRotation (Vector3.zero)
since the position of the circle is (0, 0, 0), but it didn’t work.
Any suggestions?
LookRotation takes a direction not a position. You can solve your problems one of two ways. Either you can use Transform.LookAt() (which does take a postion), or you can calculate a direction vector for LookRotation(). If the position to look at is always the origin (Vector3.zero), then you can use the negated position you use for placing your object. Without seeing your code, it is hard to be specific, but say you place one of the arrows at (0,0,5). You could do something like:
var pos = Vector3(0,0,5);
Instantiate(prefab, pos, Quaternion.LookRotation(-pos));
Again, the LookRotation() will take the negative of whatever position you use to place your Instantiated object.
i know this is an old post but if anyone still needs to do something similar here is some code.
void DrawCircleVectors(int points, float radius, Transform center1)
{
float slice = 2 * Mathf.PI / points;
for (int i = 0; i < points; i++)
{
float angle = slice * i;
float newX = (float)(center1.position.x + radius * Mathf.Cos(angle));
float newz = (float)(center1.position.z + radius * Mathf.Sin(angle));
Vector3 p = new Vector3(newX, center1.position.y, newz);
GameObject go = Instantiate(prefab,p,Quaternion.LookRotation(p,center1.position));
go.transform.SetParent(center1);
}
}