# Having an issue Making a second ray cast with a new angle

Admittedly I am new to this stuff so I may not use the right terminology and I I apologize ahead of time for messy code. So I am initially shooting a ray off that relates to a LineRenderer (lr) from my player’s transform.position. The first ray works great, it goes until hit simply hits something. However, my intention is to have this ray bounce like light would, so I went about finding the angle of incidence in relation to the Y axis. However, I can’t for the life of me figure out how to keep this line going.

I have given up on the initial ray attempt and have been simply trying to use a debug.drawline function to mimic the line to see if my current setup is even correct. There is no luck there either, I “think” I might be able to figure things out if I simply get some help with getting the debug.line to output correctly.

``````private void FireLaser()
{
lr.enabled = true;
RaycastHit2D hit = Physics2D.Raycast(transform.position, transform.up);

laserHit.position = hit.point;
lr.SetPosition(0, transform.position);
lr.SetPosition(1, laserHit.position);

Debug.Log("TRANSFORM UP IS : " + transform.up);
Debug.Log("HIT POSITION IS : " + laserHit.position);
Debug.Log("STARTING POSITION IS : " + transform.position);
Vector3 math = laserHit.position - transform.position;
Debug.Log("HIT - STARTING is : " + math);
float alpha = Mathf.Atan2(laserHit.position.y - transform.position.y, laserHit.position.x - transform.position.x) * Mathf.Rad2Deg;
float theta = 180 - 90 - alpha;
Debug.Log("ANGLE IN RELATION TO Y : " + theta);

Vector3 bouncePoint = laserHit.position;
lr.transform.Rotate(Vector3.up, theta);
//hit = Physics2D.Raycast(laserHit.position, transform.right * -theta);
Debug.DrawLine(bouncePoint, transform.up * -theta, Color.blue);
}
``````

I am aware that I don’t have a system setup up there to add on to my ray’s elements to continue the line. I was working with attempting a whole new line by using this if statement below, but as I said I have temporarily given up on this part to try and get the drawline to work.

``````if (hit.collider.tag == "Reflector")
{

Debug.Log("REFLECTED");
//HitDetect(hit);
RaycastHit2D ReflecHit = Physics2D.Raycast(laserHit.position, transform.up);
laserHit.position = ReflecHit.point;
k = lr.positionCount + 1;
lr.positionCount = k;
// lr.SetPosition(k, laserHit.position);

}
else
{
Reflecting = false;
//Debug.Log("done");
return;
}
``````

I am not good at the math you did, but I’ll point some things out.

``````//hit = Physics2D.Raycast(laserHit.position, transform.right * -theta);
Debug.DrawLine(bouncePoint, transform.up * -theta, Color.blue);
``````

Raycast’s second parameter accepts direction so that’s right, but DrawLine’s second parameter should be destination position, not direction.

``````k = lr.positionCount + 1;
lr.positionCount = k;
// lr.SetPosition(k, laserHit.position);
``````

You want to add another position in Line Renderer. However in SetPosition() you have k (which should be k-1). You forget that arrays’ index starts from 0, not 1.