Hello, Aron,

I wanted to inquire about the ConnectTiles function that generates connections between nodes. I’m trying to figure out how it’s set up because it’s quite complex. I’m particularly interested in the part that creates connections between the tiles because, as it stands, they don’t always line up perfectly. My approach with raycasts works, but it seems a bit excessive and makeshift for my taste. I’d like to explore other possibilities. One active issue I’ve noticed, as you mentioned, is that 90-degree angles are poorly handled.

For tiles that are adjacent, their shared edge is checked, and if one exists, a connection between their centers is created. However, this does not take into account the angle at which the meshes are positioned relative to each other. As a result, connections are made through invisible parts of the mesh at corners.

I want to address and process this in the construction of connections, but I’m not sure if I’m looking in the right place. Is there perhaps a modifier that affects this? Or has someone already tackled this issue?

```
if (maxalt > minalt2 && minalt < maxalt2) {
// The two nodes seem to be adjacent
// Test shortest distance between the segments (first test if they are equal since that is much faster and pretty common)
bool identical = (aVertex1 == bVertex1 && aVertex2 == bVertex2) || (aVertex1 == bVertex2 && aVertex2 == bVertex1);
if (maxalt > minalt2 && minalt < maxalt2 && (identical || VectorMath.SqrDistanceSegmentSegment((Vector3)aVertex1, (Vector3)aVertex2, (Vector3)bVertex1, (Vector3)bVertex2) < maxTileConnectionEdgeDistance*maxTileConnectionEdgeDistance)) {
Vector3 normalA = CalculateSurfaceNormal(
(Vector3)nodeA.GetVertex(0),
(Vector3)nodeA.GetVertex(1),
(Vector3)nodeA.GetVertex(2)
);
Vector3 normalB = CalculateSurfaceNormal(
(Vector3)nodeB.GetVertex(0),
(Vector3)nodeB.GetVertex(1),
(Vector3)nodeB.GetVertex(2)
);
float angle = Vector3.Angle(normalA, normalB);
if (angle > 140) {
uint cost = (uint)(nodeA.position - nodeB.position).costMagnitude;
nodeA.AddPartialConnection(nodeB, cost, Connection.PackShapeEdgeInfo((byte)a, (byte)b, identical, true, true));
nodeB.AddPartialConnection(nodeA, cost, Connection.PackShapeEdgeInfo((byte)b, (byte)a, identical, true, true));
}
}
}
public static Vector3 CalculateSurfaceNormal(Vector3 vertex1, Vector3 vertex2, Vector3 vertex3) {
Vector3 side1 = vertex2 - vertex1;
Vector3 side2 = vertex3 - vertex1;
return Vector3.Cross(side1, side2).normalized;
}
```