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
  Getting Distance from a World Point zorksox 3 5 04-16-2024, 07:30 PM
Last Post: _Aka_
  Avoiding runtime GC allocations on control point position change Ell223 8 18 02-24-2024, 10:43 AM
Last Post: _Aka_
  Removing the objects behind an object alms94 6 6 12-06-2023, 09:31 PM
Last Post: _Aka_
  Connection "next' control point jh092 3 15 11-22-2023, 11:47 AM
Last Post: _Aka_

Forum Jump: