Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

line Renderer making loop..

Discussion in 'Scripting' started by EliJNemer, May 18, 2020.

  1. EliJNemer

    EliJNemer

    Joined:
    Aug 3, 2019
    Posts:
    123
    hi,

    could anyone tell me why this is happening..

    Untitled.png

    in the Image it is shows the positions of the Line Render Vertexes:

    0) CueBall Origin
    1) ghost CueBAll
    2) Center Of Collision Ball
    3) Direction along the Vector between ghost and collision ball

    but then there is an extra line leading back to the cueBall origin (0)...


    here is the code for creating the vertexes of the line renderer:

    Code (CSharp):
    1. IEnumerator CueBallTrajectory()
    2.     {
    3.         line.enabled = true;
    4.        
    5.         Ray ray = new Ray(transform.position, transform.right);
    6.         Ray ray2;
    7.         line.SetPosition(0, ray.origin);
    8.        
    9.         if(Physics.SphereCast(ray.origin, CUE_BALL_RADIUS, ray.direction, out hitInfo, 8))
    10.         {
    11.             centerOnCollision = SphereCastCenterOnCollision(ray.origin, transform.right, hitInfo.distance);
    12.             Vector3 lineRenderDistance = LineRendererDistance(ray.origin, transform.right, hitInfo.distance);
    13.            
    14.  
    15.             ghostCueBall.transform.position = centerOnCollision;
    16.             line.SetPosition(1, lineRenderDistance);
    17.             line.SetPosition(2, centerOnCollision);
    18.  
    19.             Vector3 Heading = new Vector3(hitInfo.collider.gameObject.transform.position.x - centerOnCollision.x, hitInfo.collider.gameObject.transform.position.y - centerOnCollision.y, hitInfo.collider.gameObject.transform.position.z - centerOnCollision.z).normalized * 2;
    20.             Vector3 position3 = new Vector3(hitInfo.collider.gameObject.transform.position.x + (Heading.x / Heading.magnitude), hitInfo.collider.gameObject.transform.position.y + (Heading.y / Heading.magnitude), hitInfo.collider.gameObject.transform.position.z + (Heading.z / Heading.magnitude));
    21.             line.SetPosition(3, position3);
    22.             //ray2 = new Ray(centerOnCollision, new Vector3(hitInfo.collider.gameObject.transform.position.x - centerOnCollision.x, hitInfo.collider.gameObject.transform.position.y - centerOnCollision.y, hitInfo.collider.gameObject.transform.position.z - centerOnCollision.z).normalized);
    23.  
    24.            
    25.             //line.SetPosition(4, ray2.GetPoint(1));
    26.  
    27.            
    28.         }else
    29.         {
    30.             line.SetPosition(1, ray.GetPoint(8));
    31.             line.SetPosition(2, ray.GetPoint(8));
    32.             line.SetPosition(3, ray.GetPoint(8));
    33.             line.SetPosition(4, ray.GetPoint(8));
    34.  
    35.         }
    36.         yield return null;
    37.     }
     
  2. EliJNemer

    EliJNemer

    Joined:
    Aug 3, 2019
    Posts:
    123
    Found the Loop Button..
     
  3. amxxvi

    amxxvi

    Joined:
    Dec 23, 2017
    Posts:
    11
    Mine's still making a loop and I don't have that checkbox checked!
     
    SeryiL34 likes this.