Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
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: alt text

If I set amount of reflections to 1, dotted line renderer looks fine: alt text

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
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image xxmariofer · Jun 07, 2021 at 08:54 AM 0
Share

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.

avatar image RgClube xxmariofer · Jun 07, 2021 at 03:01 PM 0
Share

Good point, but i decided to completely give up from using line renderers :)

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

120 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Create a 2D line reflection (laser trace) 1 Answer

How to refract a linerenderer through a 2d object using Physics2D ? 0 Answers

Laser Render Reflect Angle incorrect 1 Answer

Create a sine wave(using line renderer) and reflect it from colliders 0 Answers

Line Renderer flickering when updated in runtime 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges