Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to modify Example 12 to work bi-directionally and more than 2 connected splines
Hi there,

And my apologies for having to ask for help.  I have been wanting to create a simple train track scenario with many track junctions and a bidirectional behaving train with no train cars but the ability to go in any direction.  First thing I noticed is that the example E12 is designed for one way operation only because I tried to, and it just would not work in reverse direction with a second controllable junction. I was hoping that E12 example was using a generic train controller I could use but it does not appear to work.  So, I have attempted to create my own solution based on your scripts, but I have hit a snag! I have managed to get the train controller to behave correctly when a junction is only made up of 2 connected splines but anything more than 2 (3+) then I get odd behaviours in track selection. I am not the best coder and I am sure it is my fault but any advice you can give would be appreciated.

I have attached a document with some pictures and text to help explain the two scenarios that I have been testing.

.docx   E12 Track Junction testing.docx (Size: 942.76 KB / Downloads: 4)

I know that the solution is to not use any more than 2 splines but there are going to be situations where I need to have more than 2 connections and I need to figure out how to get the train to work generically for any number of connections, within reason ofc.

If you could read my doc and then give me some pointers or maybe there is already a generic train controller on the forum that has already been written?



What you need is to set your own connections handling logic. The junction script is just an example that is meant for two splines, and is not supposed to be the fondation for elaborate connections.
To set your own connections handling logic, please refer to this:
and specifically, the Custom value. Reading the documentation of the ConnectedControlPointsSelector class should make things clear to you. If not, please let me know.

I hope this helped
Have a nice day
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Thumbs Up 
Hi aka,

thanks for the response and I have had a look and I am not really sure how to approach this but I will have a good go.  So for a simple example, if I was going to create a new custom connection type that selected the next random control point from the connection list, I could just copy the block of code in your controller script HandleRandomConnectionBehavior() and place that into a new private function in a new ConnectedControlPointsSelector class script? 

I notice that when I select "Custom" it also removes Allow direction change, Reject current spline, Reject divergent spline and Max Angle. Would I need to copy the code for these into the new script or are they still available to be used outside of the new script?

I am sorry to ask these additional questions but once I have a templated idea of how you would approach this then I can maybe work through what the custom connection logic will need to be to satisfy the requirement. My need is pretty straight forward, there is always a straight on spline or a junction spline to take depending on the state of E12_MD Junction Controller so I guess the list of connections and their position in the list will determine the selected spline?  e.g 0 = existing spline (which will never be selected) , 1 = straight on spline and 2 = junction spline?

Anyway, thank you for the pointers.


ConnectedControlPointsSelector is an abstract class, which means you can't instanciate it directly. You need to inherit from it. To inherit from an abstract class, you need to implement its abstract method, namely SelectConnectedControlPoint in this case. That method's parameter and goals are explained in the documentation.

In that method, you are free to do whatever you want, as long as it is doable with the method's inputs. So yes, you can reproduce exactly the preset connection handling logics (Current Spline, Random Spline, ...) from spline controller if you want to. It will not be by simply doing a copy/past, you will need to format the code to use the SelectConnectedControlPoint inputs.

The preset connection handling logics have their parameters, such as "Reject current spline". From the moment you don't use a preset connection handling logic, those parameters are not used anymore. That's why they disappear from the UI. So in your example of reproducing a preset handling logic via a ConnectedControlPointsSelector instance, you will need to have your own parameters.

An example of a custom logic would be to check the junction script associated with the current connection, and based on its boolean either choose the spline that is diverging or not.

I hope this helped
Have a nice day
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.

Possibly Related Threads…
Thread Author Replies Views Last Post
Information New free asset: Converter For Unity Splines _Aka_ 11 28 Yesterday, 02:24 PM
Last Post: _Aka_
  How to get length starting from one spline to connected nth spline Dragon-3623 1 1 05-14-2024, 04:52 PM
Last Post: _Aka_
  Twisting Splines ZiggZagg 6 11 05-14-2024, 04:48 PM
Last Post: _Aka_
  Help with procedural roads and splines ramiroflores 1 6 05-07-2024, 08:57 AM
Last Post: _Aka_

Forum Jump: