I’ve spent a lot of time on drawing a 2D circle using the LineRenderer. Now I want that circle to follow my character. Shouldn’t be that hard, right?
Well… I’ve tried parenting the component, I’ve tried synchronizing it with the position of the parent (see code below) but the circle stays where it is.
Can anyone please help me?
// Get the LineRenderer component
LineRenderer lr = transform.GetComponent<LineRenderer>();
// Draw the circle using that LineRenderer
DrawCircle(lr);
// Set the position
lr.transform.position = lr.transform.parent.transform.position;
And here is the DrawCircle() method:
void DrawCircle(LineRenderer lr)
{
// Calculate each point (theta) in the circle
// And set its position in the LineRenderer
int i = 0;
for(float theta = 0f; theta < (2*Mathf.PI); theta += theta_scale)
{
// Calculate position of point
float x = (radCircle*100) * Mathf.Cos(theta);
float y = (radCircle*100) * Mathf.Sin(theta);
// Set the position of this point
Vector3 pos = new Vector3(x, y, 1);
lr.SetPosition(i, pos);
i++;
}
}