i have a code to get some closest neighbour of node with waypoints and raycast. the “a” picture is the picture of waypoints location(the grey dot) that supposed to cast a raycast to each waypoints and the “b” is an image of raycast results, it’s miss on several spot(red circled). it has at about 89 waypoints, and each waypoints location is right. this is a part of my code
for(flag = 0; flag< wayPoints.WPList.Length; flag++) // iteration to seek neighbour nodes
{
for (flagNeigh = 0; flagNeigh < wayPoints.WPList.Length; flagNeigh++)
{
if (wayPoints.WPList[flag].loc != wayPoints.WPList[flagNeigh].loc) // dump its own node location
{
if (Physics.Raycast(wayPoints.WPList[flag].loc.position, wayPoints.WPList[flagNeigh].loc.position, out hitted, Vector3.Distance(wayPoints.WPList[flag].loc.position, wayPoints.WPList[flagNeigh].loc.position))) // raycasting to each node else its self
{
Debug.DrawLine(wayPoints.WPList[flag].loc.position, hitted.collider.gameObject.transform.position);
}
}
}
}
Edit : X.X.loc is location which is in Transform.
i put this part of function in Start().
The y posisition of each waypoints is the same at 2, the x and z position difeerent as in the picture “a”.
am i missing something ?
[a]. waypoints location
[5478-a.jpg**|5478]
. raycast results
[5488-bc.jpg|5488]**
**
**
[3]: /storage/temp/5480-b.jpg