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
#1
Question 
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: 3)

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?



Thanks.



Dan
Reply
#2
Hi

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:
https://curvyeditor.com/documentation/controllers/start?redirect=1#connections_handling
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.
Reply
#3
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.

D
Reply
#4
Hi

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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Video How do I merge splines only if some control points are at the sam position? arcade.autumn 2 3 9 hours ago
Last Post: arcade.autumn
  Way to make gameobject follow splines 'human-ly'? yun844 3 5 01-17-2023, 10:18 AM
Last Post: _Aka_
Rainbow Parallel Splines etoreo 1 5 01-05-2023, 09:13 AM
Last Post: _Aka_
Exclamation Stack overflow when editing prefab containing splines rhys_vdw 4 11 11-30-2022, 11:38 AM
Last Post: _Aka_

Forum Jump: