line renderer jumps when start and end positons belong to moving objects

i’m working on a 3d radar for my space game. i wrote a (simple) script for a line renderer which uses my enemy-radar-cube as startpos. and my player-radar-cube as its endpos.
it works but not really correctly. seems to me that the pos-calcuting wont be done fast enough the faster my ship moves or whatever. i dont know anymore how to fix this :frowning:

using UnityEngine;

public class eny_line_renderer : MonoBehaviour {

    public  GameObject thisobject;  // my enemy radar cube
    public GameObject center;       // my player radar cube
    public float startwidth;
    public float endwidth;

    public Color c1 = Color.yellow;
    public Color c2 = Color.yellow;
    public Color c3 = Color.green;
    public Color c4 = Color.green;

    public Vector3 pos_start_pt;
    public Vector3 pos_end_pt;

    private float thisobject_x;
    private float thisobject_y;
    private float thisobject_z;

    // private float center_x;
    private float center_y;
    private float center_z;

	// Update is called once per frame
	void Update ()
    {}
    void LateUpdate()
    {
        LineRenderer lineRenderer = GetComponent<LineRenderer>();
        lineRenderer.SetWidth(startwidth, endwidth);
        lineRenderer.material = new Material(Shader.Find("Particles/Additive"));
        //center_x = center.transform.position.x;
        center_y = center.transform.position.y;
        center_z = center.transform.position.z;

        thisobject_x = thisobject.transform.position.x;
        thisobject_y = thisobject.transform.position.y;
        thisobject_z = thisobject.transform.position.z;

        pos_start_pt = new Vector3(thisobject_x, center_y, thisobject_z);
        pos_end_pt = new Vector3(thisobject_x, thisobject_y, thisobject_z);

        lineRenderer.SetPosition(0, pos_start_pt);
        lineRenderer.SetPosition(1, pos_end_pt);

        if (thisobject_z >= center_z)        // in front of 
        {
            lineRenderer.SetColors(c3, c4); // = green
        }
        else                                // behind of 
        {
            lineRenderer.SetColors(c1, c2); // = yellow
        }
    }
}

thx for your quick answers !
now that you’ve mentioned it really seems they “jump” from an old pos. to a new pos.
i’ve tried yours but the problem is still there. Have to say that i’m (still) a beginner and so may i please you for help in : how to store a line rend. reference and if it will be necessary how to store a recent position and calculating the new pos ?
P.S.: i’m not really familar in vector mathematics so although this kind of script seems to be more complex its easier to comprehend calculating positions for each axes than to work with vector commands i dont really know what they are “doing”.

to make things a bit clearer here is my script which i attached to the enemy:

using UnityEngine;

public class Eny_rad_follow : MonoBehaviour
{
    public GameObject Player;
    public GameObject RadarCenter;
    public GameObject enemy;
    public GameObject eny_rad_cube;

    public Transform rad_transform; // the eny_rad_cube transform

    // the limit of the distance the eny_rad_cube moves  
    public float range = 2.0f;
   
    private float player_X;
    private float player_Y;
    private float player_Z;

    private float enemy_X;
    private float enemy_Y;
    private float enemy_Z;

    private float orig_dist_X;
    private float orig_dist_Y;
    private float orig_dist_Z;

    private float radar_dist_X;
    private float radar_dist_Y;
    private float radar_dist_Z;

    private float rad_Cent_X;
    private float rad_Cent_Y;
    private float rad_Cent_Z;

    private float eny_rad_cube_X;
    private float eny_rad_cube_Y;
    private float eny_rad_cube_Z;

    private float newPos_X;
    private float newPos_Y;
    private float newPos_Z;

    void LateUpdate()
    {
        player_X = Player.transform.position.x;
        player_Y = Player.transform.position.y;
        player_Z = Player.transform.position.z;

        enemy_X = enemy.transform.position.x;
        enemy_Y = enemy.transform.position.y;
        enemy_Z = enemy.transform.position.z;

        orig_dist_X = (player_X - enemy_X);
        orig_dist_Y = (player_Y - enemy_Y);
        orig_dist_Z = (player_Z - enemy_Z);

        rad_Cent_X = RadarCenter.transform.position.x;
        rad_Cent_Y = RadarCenter.transform.position.y;
        rad_Cent_Z = RadarCenter.transform.position.z;

        if (orig_dist_X >= range)
        {
            orig_dist_X = range;
        }

        if (orig_dist_X <= -range)
        {
            orig_dist_X = -range;
        }

        if (orig_dist_Y >= range)
        {
            orig_dist_Y = range;
        }

        if (orig_dist_Y <= -range)
        {
            orig_dist_Y = -range;
        }

        if (orig_dist_Z >= range)
        {
            orig_dist_Z = range;
        }
        if (orig_dist_Z <= -range)
        {
            orig_dist_Z = -range;
        }

        radar_dist_X = (orig_dist_X * 0.2f);  // *0.2 reduces the  original speed of the enemy obj 
        radar_dist_Y = (orig_dist_Y * 0.2f);  // to the enymy radar cube
        radar_dist_Z = (orig_dist_Z * 0.2f); //  just my personal impression but seems to fit well

        newPos_X = (rad_Cent_X - radar_dist_X) ;
        newPos_Y = (rad_Cent_Y - radar_dist_Y) ;
        newPos_Z = (rad_Cent_Z - radar_dist_Z);

        rad_transform.position = new Vector3((newPos_X), (newPos_Y), (newPos_Z));
    }
}

Updated: after going on with “my game” the same prob happened again. It turned out that the problem was that the radar cube has been a child of my enemy ship. Seems the position wasn’t updated fast enough so i made it independant. as well as its doesnt rotate anymore accordingly to the enemy ship which isnt necessary in the “radar”. i set the code back in the update function and now its working perfectly :)"