Hi
I have a setup of connected nodes via segments - these segments travel in any direction (think of like a connected road network).
My problem is how to accurately do collision checks for these segments and nodes.
Additionally some segments are curved via bezier curves which adds to the complexity of collision detection.
There are 2 types of issues i do not know how to solve:
1) User clicking with the mouse and detecting a node or a segment (for example adding a new road branching off an existing node or segment). Since adding a branch to a segment, would need to insert a new node and split the selected segment.
2) Detecting if a segment collides with another segment when trying to add a new one at run time.
My code setup is:
public struct Node
{
public Vector3 Position { private set; get; }
//list of segments node is connected to
public Segment?[] Connections_Segments { private set; get; } //max 4 size
//list of nodes connected to - useful for pathfinder
public Node?[] Connections_Nodes { private set; get; } //max 4 size
//constructor etc etc
}
public struct Segment
{
public Node[] Nodes { private set; get; } //maximum of 2 nodes
public int Thickness { set; get; } //thickness of the road i.e 2 lane, 4 lane etc
public Vector3 AnchorPoint {private set; get; } //TODO bezier curve
//constructor etc etc
}
Some things i thought about and tried but didn't work:
I added bounds to both nodes and segments, but soon realised this made no sense. In Unity bounds are axis aligned, this is no good for roads that do not follow along an axis (curved roads or roads going diagonally).
I also thought about using quad tree which only makes sense if the roads are straight, but they are obviously curved. And again using bounds is axis aligned so it won't be able to accurate represent roads that do not follow an axis (such as curved segments and diagonal segments).
So i am bit lost now what else to try. Hoping some one who has experience with design problems may have some suggestions that I can try.