- Home /
Question by
RgClube · Jun 05, 2021 at 11:23 AM ·
linerendererreflectionbouncing
How to prevent line renderer from stretching after reflection
I have problem with line renderer it stretching dots after reflection from the wall. I've tried different solutions that the internet has to offer, but none of them work. Here is how it looks:
If I set amount of reflections to 1, dotted line renderer looks fine:
Here is the script that i use to make reflected dotted line:
if(Input.GetMouseButtonDown(0))
{
Vector3 touchPos = Input.mousePosition;
Vector3 pos = Camera.main.ScreenToWorldPoint(touchPos);
direction =(pos - startPosition).normalized;
ray = new Ray2D (startPosition, direction);
lineRenderer.positionCount =1;
lineRenderer.SetPosition(0, startPosition);
float remainingLength = maxStepDistance;
for (int i = 0; i < reflections; i++)
{
RaycastHit2D hit = Physics2D.Raycast(ray.origin, ray.direction, remainingLength);
if(hit.collider.gameObject.tag == "Bounds")
{
lineRenderer.positionCount +=1;
if(i== reflections-1)
{
lastPosition = hit.point;
}
lineRenderer.SetPosition(lineRenderer.positionCount -1, hit.point);
remainingLength -= Vector3.Distance(ray.origin, hit.point);
ray = new Ray2D(hit.point - ray.direction * 0.01f, Vector3.Reflect(ray.direction, hit.normal));
}
else
{
lineRenderer.positionCount +=1;
lineRenderer.SetPosition(lineRenderer.positionCount -1, ray.origin + ray.direction * remainingLength);
}
}
rend.material.mainTextureScale = new Vector2(Vector2.Distance(lineRenderer.GetPosition(0), lineRenderer.GetPosition(lineRenderer.positionCount - 1)),1);
}
Line renderer texture mode set to Tile mode, Dot texture Wrap mode set to Repeat.
Please help if you have any solutions!
skwegelr.jpg
(6.2 kB)
ixwmo4vq.jpg
(5.7 kB)
Comment
Im not experienced enough with line renderers, but have you consider using multiple line renderers for reflections? I doubt there is a performance penalty unless you need to add docens of them.
Good point, but i decided to completely give up from using line renderers :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613034627im_/https://answers.unity.com/themes/thub/images/avi.jpg)