Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Difficulty with connections
#1
I'm trying to create a train track with connections that only allow certain ways so that the train doesn't bend like 130 degrees to follow a path even when traveling backwards, just like you've done in your connection/space example. On top of that i'd like to create logic for switching tracks. I'm having some trouble with your UI, i'm not sure what things mean with all the checkboxes. I couldn't find any documentation/videos on it either.
[Image: 8mQ4TrO.jpg]

I'm able to get a few things working except for this:
[Image: igNoUgj.jpg]
As the train travels up from the bottom of the screen i'd like it to continue along the same track. Currently it jumps to the other track and furthermore it jumps to the other end as you can see in the image, and i'm not sure why because that node doesn't have a connection. 

Here is my code:
Code:
public class TrainConnectionDecider : ConnectedControlPointsSelector
{
    public override CurvySplineSegment SelectConnectedControlPoint(SplineController caller, CurvyConnection connection, CurvySplineSegment currentControlPoint)
    {   
        MDJunctionControl jc = currentControlPoint.GetMetadata<MDJunctionControl>();
        if (jc && jc.UseJunction != false)
        {
            return connection.ControlPoints[connection.ControlPoints.Count-1];
        }
        return connection.ControlPoints[0];
    }
}

I believe I can achieve this using your directional based UI instead of writing further code and complicating things. But I haven't been able to yet.

Looking for any help. Thank you.
Reply
#2
Hi,
  • Here is the documentation for the connections: https://curvyeditor.com/documentation/sp...onnections
  • Your TrainConnectionDecider selects either the first or last Control Point of the connection's CPs. I would not advise you to code it like that, because it makes assumptions about the order of the CPs in that list. It is better to make the code select either the current CP, or the other CP, by doing the right equality checks. This way of doing will stay correct whatever the order of the CPs in the list. This probably explains why your train changes track while you want it to stay on the same track.
  • The train jumps to the other end of the spline because I suppose that you connected your main track's CP with the last CP of the other track. So the train changes track, and finds itself at the last CP of the new track. It then loops to the start of the track. To fix this, either connect the main track's CP with the first CP of the secondary track, or make your connection handling code change the direction of the train when it changes the track.
You don't have to code your own diverging spline rejecting code, and direction changing code, these are already coded. You can find them in SplineController methods GetAngleBetweenConnectedSplinesGetPostConnectionDirection. An example of their usage is in the HandleRandomConnectionBehavior method. Some of the cited methods are private.

If after applying the above you still have issues, please write me back with preferably the scene you are working with.

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
  Connections/Controller issue lllApOlll 3 993 03-05-2018, 07:30 PM
Last Post: _Aka_
Question Connections - Can someone please explain how these work? atomsinthevoid 3 1,086 10-20-2017, 10:27 PM
Last Post: atomsinthevoid
  Sync MetaData for Connections MrPotatoStealer 1 706 06-21-2017, 07:12 PM
Last Post: Jake
  one-way connections otez.jedi 4 1,991 09-05-2016, 08:01 AM
Last Post: otez.jedi

Forum Jump: