Navmesh.Linecast help

Hi, I’ve updated from version 4.2.18 to 4.3.74, and it seems that the Linecast isn’t working the same way as before.

If I understand correctly from the documentation, it should check for any obstacles between two points.

Returns if there is an obstacle between origin and end on the graph.
This is not the same as Physics.Linecast, this function traverses the graph and looks for collisions instead of checking for collider intersection.

To ensure that none of my other scripts are affecting the linecast in a negative way, I have created a simple script and implemented it in a new scene.

Here is the script:

public class Test : MonoBehaviour
{
    public Transform a;
    public Transform b;
    public Transform c;
    void Update()
    {
        var nearest = AstarPath.active.data.navmesh.GetNearest(a.position, NNConstraint.None).node;
        bool obstacle = AstarPath.active.data.navmesh.Linecast(a.position, b.position, nearest, out var hit);
        c.position = hit.point;
        Debug.Log("Obstacle: " + obstacle + " on: " + hit.point);
        Debug.DrawLine(a.position, b.position, obstacle ? Color.red : Color.green);
    }
}

When I execute this code, the linecast always returns true (obstacle) even if there is no obstacle between the two given points.

The only time it doesn’t return true is when the two points lie within the same triangle.

Here is a GIF showing the issue:

These are my A* settings:

Used “mesh asset”

Same test in 4.2.18

Could anyone help me with this issue?

Thanks in advance,

Julen.

Has anyone else encountered this issue?

I’m unable to resolve it.

Hi

Thank you! I have managed to replicate this and found the bug.
This was a regression in a recent 4.3.x version.

The fix will be included in the next beta update.
In the meantime, a workaround is to ensure that all triangles have their vertices laid out clockwise in the xz plane.

1 Like