07-14-2020, 12:25 AM
OK I have pretty much got there I think, I'll put the code below roughly in case it helps anyone in the future. I have given the stations a Spline ref so they "know" what spline they are on, and then when the train hits a trigger child of the connection point it checks if its current spline = the spline of the station for its next stop, then checks if the controlpoint[0] on the connection = the station spline and if not switches it. It all seems to work, but eventually I will need this to work out possible routes when there is more than 1 connection between the station and the controller, so if anyone can help with the logic behind that it'd be great!
I added this to JunctionSwitch.cs (really messy code that could be improved a lot I know!)
I added this to JunctionSwitch.cs (really messy code that could be improved a lot I know!)
Code:
private void OnTriggerEnter(Collider collision)
{
if (collision.gameObject.tag=="Train")
{
//if trains next station spline != trains current spline
if(collision.gameObject.transform.parent.GetComponentInParent<TrainRouting>().scheduledStops[0].GetComponent<StationManager>().Spline != collision.gameObject.GetComponent<SplineController>().Spline)
{
// check if connection controlpoint[0] is the right spline for the station spline and switch if not
if (GetComponentInParent<CurvySplineSegment>().Connection.ControlPointsList[0] != collision.gameObject.transform.parent.GetComponentInParent<TrainRouting>().scheduledStops[0].GetComponent<StationManager>().Spline)
{
GetComponentInParent<MDJunctionControl>().UseJunction = !GetComponentInParent<MDJunctionControl>().UseJunction;
}
}
}
}