How do I draw a local space line render between parent and child objects ?

Hi , I really need some help here

I’m just trying o draw a lical space line renderer between the pare and child objects , but it is just not drawing the line correctly no matter what i try.

here is my script

To use this script , you must

1 create a cube and a sphere.

2 make the sphere a child of the cube.

3 add the script to the cube.

4 set the position of the sphere to (0,3,0)

public class AddLine : MonoBehaviour {

public Transform Ball;

void Start()
    LineRenderer line = Ball.gameObject.AddComponent<LineRenderer>();
    line.SetWidth(0.015F, 0.015F);
    // we want the lines to use local space and not world space
    line.useWorldSpace = false;
    line.useLightProbes = false;
    line.receiveShadows = false;
    line.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
    line.material.color =;

void FixedUpdate ()
        // begin the line at the cubes position
         Vector3 Start =  new Vector3 (transform.position.x, transform.position.y, transform.position.z);

        // to that the line ends at the center of the ball
        Vector3 End = new Vector3();

        //Set the begin and the end of the line renderer
        Ball.GetComponent<LineRenderer>().SetPosition(0, Start);
        Ball.GetComponent<LineRenderer>().SetPosition(1, End);




About Fixed Update, check this out: (1) or this (2)

you should use Update instead.

to get your starting point (in local space) use: Vector 3 Start =;
which is actually your end point :stuck_out_tongue:

to get your end point use: Vector 3 End = Ball.position - transform.position
its possible that this will not work if you use some kind of scaling or rotating, so its more safe if you use:

Vector3 End = transform.worldToLocalMatrix.MultiplyPoint(Ball.position);

**edit: ** *since your Ball is a child of the Cube you can simply use: *

Vector3 End = Ball.localPosition;

if you would use a world space line renderer you could simply use:

Vector3 Start = transform.position;
Vector3 End = Ball.position;