Can't get line renderer to stop at walls

I’m using a line renderer as a laser sight but can’t figure out how to get it to stop at colliders. I’m using the below code

RaycastHit hit;
Vector3 aimDir = -transform.parent.TransformDirection(Vector3.up) * 100;
//Debug.DrawRay(transform.position, aimDir,;

if(Physics.Raycast(transform.position, aimDir, out hit, 1000f, 9)){
    Debug.Log("laser sight hit " + hit.transform.position);
    Debug.Log("laser sight hit " +;
    lineRenderer.SetPosition(1, hit.transform.position);

However as per the below screenshot it just goes backwards. I’ve confirmed aimDir is correct through Debug.DrawRay but the line renderer seems to go to a random position. What am I doing wrong?

In your example you don’t set position for index 0 … you should probably set that to your guns laser pointers position as I think it would just get set to origin otherwise.
lineRenderer.SetPosition(0, positionOfStartOfLine);