Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Connections - Can someone please explain how these work?
#1
Question 
So I'm going to branch off to multiple paths, and the user can choose which direction to go ahead of the path.  Seems like "Connections" is what I want to do.  But I'm confused, and maybe even worried there's something wrong.

When I look at the demos, say, 12-Train, it's pretty similar to what I want (except I don't use trains lol).  The Connection on PathA/CP0002 has two Connections, PathA and PathB.

How do I actually set that up!?  If I make two curves, then create a connection on one of those nodes.. it does not let me "Head to" anything (drop down exists but no options).

The documentation doesn't help at all, it barely explains what this does and how to work it, and certainly makes no effort to give a step by step on setting this up.  The videos don't seem to talk about this.  I find this pretty strange because it seems like such a vital feature.  

Looking forward to some help on this one, as it's pivotal for my game.
Reply
#2
To create connections, just select all CP's you want to become part of the connection, then click "Connect".

Does that help?
Reply
#3
(10-19-2017, 06:10 PM)Jake Wrote: To create connections, just select all CP's you want to become part of the connection, then click "Connect".

Does that help?

Hah.  Ok that works, wow.. completely not obvious!  That should be a tool tip above the button Smile

That said, what's the best approach to this?  Basically I have my character running forward and I want to give them the ability to branch left or right and go off to different splines.  Can I have the spline directly split off at there, or do I need to create a full loop per split?
Reply
#4
Ok so after diving deep into the train example I finally isolated the code that figures out if the junction should be used or not.  I feel like I'm in the brain of a madman here but it's starting to make a bit of sense.  I'm still somewhat new to C# but I do get the hang of things quickly.  That said, perhaps you can help me make sense of this line of code that I found in the TrainCarManager.cs file:

Code:
       
void OnCPReached(CurvySplineMoveEventArgs e)
       {
           var jc = e.ControlPoint.GetMetadata<MDJunctionControl>();
           if (jc)
           {
               if (jc.UseJunction)
               {
                   e.Follow(e.ControlPoint.Connection.OtherControlPoints(e.ControlPoint)[0]);
                   // Set the controller to use the new spline
                   SplineController controller = (SplineController)e.Sender;
                   controller.Spline = e.Spline;
                   controller.RelativePosition = e.TF;
               }
           }
       }

So, I get that this is an event listener, and I notice that it's attached to the Spline controller of each car above via this method:

Code:
        void setController(SplineController c, CurvySpline spline, float speed)
        {
            c.Spline = spline;
            c.Speed = speed;
            c.OnControlPointReached.AddListenerOnce(OnCPReached); // RIGHT HERE
            c.OnEndReached.AddListenerOnce(CurvyDefaultEventHandler.UseFollowUpStatic);
        }

Cool.  So every control point is going to call "OnCPReached"..  Then I notice there's some metadata added on the junction which is just a bool toggle on or off, so let's not worry too much about that.  

What I want to know is what are each of these lines doing?  Especially that e.Follow one.  Of course, I know it's telling the connection to follow the "other" control point, and somehow e.ControlPoint will tell it to follow the other connection.  But how does it know that?!  I notice the [0] at the end there, is this an array?

                   e.Follow(e.ControlPoint.Connection.OtherControlPoints(e.ControlPoint)[0]);
                   // Set the controller to use the new spline
                   SplineController controller = (SplineController)e.Sender;
                   controller.Spline = e.Spline;
                   controller.RelativePosition = e.TF;

At a high level I get what's happening here, but I'd like to understand it more fundamentally since I plan to adapt this idea to my own purposes and I can't really do that until I look under the hood a bit more.

Thanks for the help!
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Difficulty with connections justinms66 1 112 08-08-2018, 11:30 AM
Last Post: _Aka_
Exclamation Connection does not work Sergei543071 5 233 07-29-2018, 08:56 PM
Last Post: _Aka_
  some stuff didnt work as excpected NV3 Developper 1 575 04-20-2018, 03:33 PM
Last Post: _Aka_
  Connections/Controller issue lllApOlll 3 666 03-05-2018, 07:30 PM
Last Post: _Aka_

Forum Jump: