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
#2
I've already started to realise that the way I've got things set up isn't perfect but not sure how else to tackle these problems.

For example if I wanted to apply the same concept in the top right connection, so that the player in the picture first selects to go left and then wants to go right at the second junction. Both left and right turns on that second junction are the same connection point from the first spline! So I can't apply my method there unless I say OK switch to the first spline AND switch direction to backwards.

Maybe setting this up as two separate loops is better where they dont have a shared middle path. Curious to know how people have something like this set up
Reply
#3
Hi Samy,
I see from the pics that each connection lead to two paths, while in the code I see code handling 3 paths. Does the game design say that there will be always only two paths (left and right)?
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#4
(11-11-2023, 01:52 PM)_Aka_ Wrote: Hi Samy,
I see from the pics that each connection lead to two paths, while in the code I see code handling 3 paths. Does the game design say that there will be always only two paths (left and right)?

Hey yah so I set it up so that if there are only two connecting options, like a fork, then I will only have to drag in two CPs and only 2 options will show on the player's screen. But on a crossroads, there may be 3 options so you might be able to choose left, middle and right so then I will have to drag in 3 CPs and the system will populate the options from the CPs. Here is an example in-game with 3 options: 

https://imgur.com/a/2AlLNUC
[Image: 2AlLNUC]

Just curious to see if there's a better way to do all of this because it seems really manual and prone to human error. For example just now when I tried to turn left, the spline is actually "backwards" so I end up teleporting to the other end of it.
Reply
#5
Hi
You can keep doing things manually while adding automatic checks. You can also try to automate the left/middle/right assignements.
Both methods will rely on the same core idea: going through all the CPs of the connections, and comparing the tangent at thoses CPS. All the tangents should be "leaving" the connection CP. The left CP should have a tangent that is to the left of the middle CP, and so on.
One thing that I think will have to be assigned manually, is the "source" CP, the one from which the player will enter the connection.
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
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: