Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Junction & Connection Navigation System Design
#1
Lightbulb 
Hello Curvy friends!  Angel

So by putting together the various replies on this forum and backsolving the examples (and some miracle) - I've managed to successfully create a user-selected navigation system for my game *gasp* 

The use case was a fairly simple one but seemed to require quite a complicated implementation - when a player approaches a junction, I wanted them to be able to select from left, middle or right paths, and the controller would switch accordingly.

Although everything works, I'm sure that there are better and simpler ways of doing some of the things I'm doing but I couldn't figure out how to do them or think of anything more efficient. So I would like to ask generally what you think of this approach and maybe this thread will be helpful for someone in the future because I struggled for a while with the design. 

Thank you! 

Below you can see the basic setup. A road network with a simple junction stemming from a connector: 

   

As you can see, I've setup a trigger on the control point before the junction. This trigger does the following:  

  1. Checks the player's direction and only responds if going forward. 
  2. Assigns the player's spline controller connection behaviour to "custom" and selects the location of the customselector script.  
  3. Loads up a toggle group of selection buttons that correspond to the paths
  4. Assigns the spline names to the button texts - I'm doing this manually for each junction by dragging in the left and right CurvySplineSegments for the connection in the inspector and then using CurvySplineSegment.spline.name. I dont necessarily mind doing this manually for each connection as it ensures I have the correct spline on the correct side.    
  5. It also looks up against a dictionary for the "default" direction for that connection name and selects that default button. 
  6. When the user selects a direction, the Curvysplinesegment associated with that direction gets temporarily stored in another function so that we can assign it in the Customcontroller later.   COOL! Exclamation

So when our player goes through the trigger, we have this! (ignore the path names lol): 

   

Next you arrive at the connection! 

Two things happen here: 
  1. Another trigger deactivates the UI buttons
  2. The customcontroller assigned from the first trigger kicks in.

As we stored which segment the user has selected, we retrieve this and assign it in the customselector code as below: 

Code:
public override CurvySplineSegment SelectConnectedControlPoint(SplineController caller, CurvyConnection connection, CurvySplineSegment currentControlPoint)
    {
        navRef = GetComponent<WGNavRef>();
        Heading = navRef.GetHeading(ConnectionNo);
        
        //Let's retrieve the CP name from the navref temp storage
        if(Heading == "L")
        {
            ChosenConnection = navRef.LeftCP;
        }
        else if (Heading == "M")
        {
            ChosenConnection = navRef.MiddleCP;
        }
        else if (Heading == "R")
        {
            ChosenConnection = navRef.RightCP;
        }
        
        //Now we convert the stored CP into a way that the controller can read - assuming this is connection.controlpointlist[x]
        foreach (CurvySplineSegment controlPoint in connection.ControlPointsList)
        {
            int index = connection.ControlPointsList.IndexOf(ChosenConnection);
            if (index != -1)
            {
                return connection.ControlPointsList[index];
            }
            else
            {
                // If the chosenConnection is not found, set ConnectionBehavior and return this
                caller.ConnectionBehavior = SplineControllerConnectionBehavior.FollowUpSpline;
                return null;
            }
        }
      // return connection.ControlPointsList[0];
      caller.ConnectionBehavior = SplineControllerConnectionBehavior.FollowUpSpline;
        return null;
    }
 
You can see that if everything fails then I am setting the default logic to the follow up spline. I found that if I reach a connection where none of this stuff is assigned it makes sure that I just continue onto the next spline. I wasnt sure how else to do this with the controlpointslist method. 

One problem with this is that even though the follow up spline will get assigned if a CP is not found then you will get an error in the inspector. I don't know enough about the complications of this to understand if it's a problem long term but for now this works.  Huh

TBH although I am quite happy that I actually managed to get there on my own I'm sure you are looking at this in absolute disgust lol and maybe there is a much better way of doing a system like this. I did see in the example that there is some eventargs method that is assigning the customcontroller behaviour from stored metadata but I wasn't able to figure out how to adapt this to my case. 

Appreciate any comments you might have. Maybe this thread can serve as a bit of a reference for those who are struggling like I did. Sleepy
 
Thanks Aka I hope you have the NICEST day xxxxx   Heart
Reply


Messages In This Thread
Junction & Connection Navigation System Design - by SAMYTHEBIGJUICY - 11-10-2023, 03:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Bug Changing spline connection in inspector causes splines to revert to defaults lacota 3 6 03-18-2024, 07:55 PM
Last Post: _Aka_
Thumbs Up Can't delete connection lacota 3 6 03-16-2024, 11:34 AM
Last Post: _Aka_
  Isolating Package to include only Spline system nichstkann 3 7 12-15-2023, 12:39 PM
Last Post: _Aka_
  Unity 2021.2 Overlay System nehvaleem 5 17 12-15-2023, 10:09 AM
Last Post: _Aka_

Forum Jump: