Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Get nearest point to a world object
#1
Rainbow 
Hi, I would like to place stations along a track and then if a train is scheduled to stop at the station next, find the nearest control point to that station, and then eventually set connections properly to make sure the train will go to the right path that this specific cp is on. I imagine this last bit will get more complicated if there are several connections before this control point as it'd need to calculate a full route not just switch a single path A or B. 

So is the easiest way to do this to make a new control point when a station is placed so a station will always be sat on its own control point which could be stored as a value the station itself, or is that not possible?

If it's not possible can I get the nearest control point based on the x,y,z of the station gameobject (which is just an object in the world its not related to the spine or anything)

And then how can I talk to the connections to make sure they are set in a way that will make the train choose the right path at a junction? Even at a basic level where there is only 2 paths A and B and it needs to choose a station on path A or B how would I set the connection to switch (or not) depending what it needs to do?

Sorry if that's sort of 2 questions in one! Any help is appreciated!

Now that I think about it maybe I don't need the nearest CP at all maybe I should just set the station to the spline it's on when placed? So if it's collider (trigger) is touching spline B it's set to that, is that possible even though the spline doesn't have colliders on it?

But then i would still need to know how to make sure the train follows the right spline to the spline that station is set to when it comes to a connection somehow...
Reply
#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
#3
Hi,
I see your problem as being two separate problems:
1- find the way between points A and B
2- make the train follow that way

Point 2 is related to Curvy. Using a mechanism similar to the Junction mechanism in the example scene 12 should do the trick.
Point 1 is a wider problem, not specific to Curvy. It's basically path finding. Since you are planning to have multiple rail roads connected, I think you better try to find an already existing path finding solution that would work good, instead of trying to invent your own path finding algorithm. I have no real experience with the path finding problematics, but I did some projects using that when student. A* algorithm was a good algorithm at that time (is there anything better since?). It's a simple algorithm, and I am sure you can easily find implementations for it using C#
I would advise you to read this: https://en.wikipedia.org/wiki/Pathfinding
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#4
(07-14-2020, 01:18 PM)_Aka_ Wrote: Hi,
I see your problem as being two separate problems:
1- find the way between points A and B
2- make the train follow that way

Point 2 is related to Curvy. Using a mechanism similar to the Junction mechanism in the example scene 12 should do the trick.
Point 1 is a wider problem, not specific to Curvy. It's basically path finding. Since you are planning to have multiple rail roads connected, I think you better try to find an already existing path finding solution that would work good, instead of trying to invent your own path finding algorithm. I have no real experience with the path finding problematics, but I did some projects using that when student. A* algorithm was a good algorithm at that time (is there anything better since?). It's a simple algorithm, and I am sure you can easily find implementations for it using C#
I would advise you to read this: https://en.wikipedia.org/wiki/Pathfinding

Hi I agree I shouldn't re-invent the wheel, it just feels like this level of AI/pathfinding should be SO simple, it's literally just got to choose path A or B and is constrained to simply moving or stopping on splines... no obstacle courses to try and work its way around or anything tricky!

I did start to look at A* as like you say I think it's considered the best, so I'll take another look, it just felt like it might be overkill for what is essentially very very limited movement and calculations literally restricted to tracks. Thanks as always for your input!
Reply
#5
I first understood that you will have a web of roads, but now I realize you are going to have a "tree" of roads (only 2 roads connections and no looping). True, there should probably be a simpler solution for this simpler case, but I don't see it right now. Probably involving a manual or automatic process to mark all the connections leading to a station with some marker (a MetaData would do the trick) to allow the train to decide where to go once reaching a connection
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#6
(07-14-2020, 08:22 PM)_Aka_ Wrote: I first understood that you will have a web of roads, but now I realize you are going to have a "tree" of roads (only 2 roads connections and no looping). True, there should probably be a simpler solution for this simpler case, but I don't see it right now. Probably involving a manual or automatic process to mark all the connections leading to a station with some marker (a MetaData would do the trick) to allow the train to decide where to go once reaching a connection

Hi, yes I like that idea, I shall look into MetaData some more! Many thanks Smile
Reply
#7
Radio audience members are profoundly responsive. What's more, radio promotions are amazing, modest, and easy to create. However radio stays one of the most underused and ineffectively took care of weapons in the immediate promoting stockpile. 

It's hard to sell an  Chile Mobile Database item straightforwardly from a radio advertisement. Be that as it may, on the off chance that you have an item with wide intrigue, you can utilize radio to produce requires your telephone reps, manufacture a standard mail list, or send traffic to your Web website.

Here are a couple of pointers for making straightforward yet successful direct reaction radio promotions:

Purchase 60-second spots. The radio salesperson will reveal to you that 30-second spots are less expensive and simpler to put. That is valid. However, 30 seconds for the most part isn't sufficiently long to create and convey a selling message. With 60-second spots, you'll get twice as much an ideal opportunity for only somewhat more cash per spot.

Utilize a straight host pitch. Individuals are working, driving, cleaning the house, and doing a wide range of things in under perfect listening conditions. So keep it straightforward. Simply have a host talk straightforwardly to audience members. This has the additional preferred position of being more close to home and more affordable than spots loaded up with entertainers and audio cues.

Distinguish and take care of an issue. In case you're selling a home grown item that gives individuals more vitality, you should initially recognize the issue (absence of vitality) at that point offer your item as the arrangement (more vitality). "Feeling tired? Throbbing? Try not to have the vitality for the things you used to appreciate? Attempt new Vita-Herb. Vita-Herb will support your vitality, delete those a throbbing painfulness, and let you appreciate life once more."

Make a sensational guarantee. This will fortify your answer and make it all the more engaging. "Vita-Herb will cause you to feel ten years more youthful in only ten days!" The more emotional and explicit your guarantee, the better.

Assurance results. Similarly as a guarantee fortifies your answer, an assurance reinforces your guarantee. Once more, be as explicit as could be expected under the circumstances. "Attempt Vita-Herb for yourself. On the off chance that you don't feel ten years more youthful in the initial ten days, simply send it back and we'll get you a jug of your preferred spice supplement. No inquiries posed."

Offer something free. Since time is short and items can't be seen on the radio, it's difficult to make direct deals. It's unmistakably progressively viable to offer data or tests to create requests at that point make deals through selling and post office based mail. In case you're selling a Posture Perfect Mattress, you could offer a free video. At that point when you send the video, you could incorporate a unique $100 reserve funds voucher. You can catch up with post office based mail, calls, and extra data and offers.

Drive audience members to your Web website. This is an option in contrast to producing requests by telephone. Try to catch data when individuals show up at your site. In case you're selling a self-concentrate seminar on beginning a business, you could offer a free report on the 25 quickest developing organizations. At that point give individuals a Web address that takes them to an uncommon page where they should enter a name and address to get the report. Thusly, you'll fabricate a database for more focused on showcasing.

Present a reasonable source of inspiration. Try not to be subtl
Reply
#8
you are welcome
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Converting spline collider hit point to spline position jh092 7 372 06-26-2020, 09:48 PM
Last Post: _Aka_
  Spline object on a spline path ATHellboy 22 4,378 03-01-2020, 05:03 PM
Last Post: _Aka_
  Convert position of a point on a spline to another spline which is connected ATHellboy 5 1,273 02-17-2020, 12:17 PM
Last Post: _Aka_
Big Grin How to get a point in Spline that is parallel with another Spline? curvyuser007 5 1,311 01-20-2020, 10:18 PM
Last Post: curvyuser007

Forum Jump: