Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get nearest point to a world object
#2
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!)





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;
                }
            }

        }
    }
Reply


Messages In This Thread
RE: Get nearest point to a world object - by jamesunity - 07-14-2020, 12:25 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Control Point Interpolation Overrides. rickgplus 1 523 12-11-2025, 08:52 AM
Last Post: _Aka_
  Create Game Object Renaming Options rickgplus 1 934 09-23-2025, 09:33 AM
Last Post: _Aka_
  12_Train junction point richardzzzarnold 5 3,408 04-16-2025, 02:19 PM
Last Post: _Aka_
  OnAfterControlPointAdded - Control Point is null jh092 5 3,173 02-04-2025, 09:31 PM
Last Post: _Aka_

Forum Jump: