Search code examples
androidunity-game-enginerenderer

Set LineRenderer position


I'm trying to set the LineRenderer position in the center of the parent but it's set in the wrong position

it's should be in this position

center

Here is the code that I tried

Vector3 SumPointsVectors = new Vector3(0f, 0f, 0f);
// filledRenderer point int Line rendere
 foreach (var child in filledRenderer)
 {
     SumPointsVectors += child;
 }

 Vector3 Center = SumPointsVectors / filledRenderer.Length;
 _lineRenderer.transform.position = Center;

Solution

  • virgilcwyile answer: The line renderer game object when you select is showing you the centre point right? So you can create a GameObject and place it in that centre point, then Make the LineRenderer a child of that GameObject. Then set this GameObject child of your Cylinder Parent. After doing that, you can reset the GameObject's position to Vector3.Zero.

    Alternate Solution: Another solution would be to create a Custom Mesh from your Points and then set the pivot.

    here the answer in unity answer http://answers.unity.com/answers/1770136/view.html