hi i have some nodes (around 5~6 ) scattred around on ground plane . which are used to generate pointgarph .
is there any way that i can draw connections with line renderer or vectrosity to show the connections .
i know its already there in debug mode and you can see it via enabling gizmos , but i dont know how that is achieved in debug mode … can you please guide me how to go about it ?
This will draw a line for all connections in the graph (actually it will draw each connection twice, it will draw it in both directions). To draw it in game you will have to change the Debug.DrawLine call to use something like Vectrosity.
Ok , the update: the above mentioned way is not quiteusefull as it gives you all random and unpredictable data
for example consider three nodes:-
A------B------C
now i am getting links between A-----B , B-------C and there reverse , which is all ok , but in some cases i am also getting links like A------------C
If it says there is a connection between A and C, then there is apparently a connection between A and C (and would also show up in the scene view). You will have to tweak the point graph settings, maybe by reducing the maximum connection distance.
A connection can go in any direction, not just four fixed ones, but you can use some code to figure out which direction is the closest. Something like this:
var connectionDir = ((Vector3)other.position - (Vector3)node.position).normalized;
var dirs = new Vector3[] { Vector3.left, Vector3.right, Vector3.up, Vector3.down };
var closest = 0;
for (int i = 0; i < dirs.Length; i++) {
if (Vector3.Dot(dirs[i], connectionDir) > Vector3.Dot(dirs[closest], connectionDir)) {
closest = i;
}
}
Debug.Log("The connection goes approximately in the " + dirs[closest] + " direction");