Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

LineCast issue

Discussion in 'Scripting' started by Sekerali, Mar 14, 2019.

  1. Sekerali

    Sekerali

    Joined:
    Mar 14, 2019
    Posts:
    2
    I have a list of nodes in the worldspace. I have code to check which nodes are visible to the player (lastseen) and store them which is as follows:

    Code (CSharp):
    1. for (int i = 0; i < CNode.Count; i++)
    2.         {
    3.             Vector3 location = CoverNode.GetChild(i).GetChild(1).position;
    4.             Vector3 direction = (lastseen - location).normalized;
    5.             Vector3 forward = (CoverNode.GetChild(i).GetChild(0).position - location).normalized;
    6.             if (Vector3.Angle(forward, direction) < 60) //if within view angle
    7.             {
    8.                 if (!Physics.Linecast(lastseen, location))
    9.                 {
    10.                     ctemp.Add(i);
    11.                     Debug.DrawLine(lastseen, location, Color.cyan, 0.1f);
    12.                 }
    13.             }
    14.         }
    This code is working perfectly and i can see the drawlines in testing. The problem is that when an ai model blocks one of the linecasts, ALL linecasts fail. Linecasts blocked by walls is not causing an issue.
    What i have tested:
    • Standing still until a line is blocked by an ai - causes all lines to stop drawing and ctemp is size 0.
    • Nodes that should be in sight fail at the linecast. The view angle works fine.
     
    Last edited: Mar 14, 2019
  2. Sekerali

    Sekerali

    Joined:
    Mar 14, 2019
    Posts:
    2
    This randomly fixed itself after moving some objects in the world space and then back to original. Im not going to attempt to recreate the problem.