Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Connections/Controller issue
#1
Hi, 

I'm currently testing Curvy to make a creature roam on a path with multiple spline connected.

Here is a screenshot of the scene with in red the path that my creature choose to follow another connected spline: 
[Image: Example.png]

Here the detail of the behavior: 
- it begins on the main spline (the white large closed spline).
- when it reachs the first connection with the blue spline, it works, it goes on it and keep following the path.
- BUG: at the end of the blue spline, it goes back on the main spline but it will teleport at the first control point and I don't understand why so I may miss something with the example I looked.

Here is the code exectued at each control point :

Code:
public void OnControlPointReached_Path(CurvySplineMoveEventArgs e)
{
    if (!e.ControlPoint.Connection)
        return;

    List<CurvySplineSegment> valideControlPoints = new List<CurvySplineSegment>();
    List<CurvySplineSegment> others = e.ControlPoint.Connection.OtherControlPoints(e.ControlPoint);

    for (int i = 0; i < others.Count; ++i)
    {
         if (e.AngleTo(others[i]) < 90) // Smooth enough
         {              
             valideControlPoints.Add(others[i]);                
         }
    }

    if (e.Spline.IsClosed || !e.ControlPoint.IsLastControlPoint) // Can continue on the same spline
    {        
         valideControlPoints.Add(e.ControlPoint); // Add current spline      
    }
    else // Must change Spline
    {
         if (valideControlPoints.Count == 0) // Find solution even if the LD is not properly setup
         {                
               CurvySplineSegment bestControlPoint = others[0];
               for (int i = 1; i < others.Count; ++i)
               {
                    if (e.AngleTo(others[i]) < e.AngleTo(bestControlPoint))
                    {
                          bestControlPoint = others[i];
                    }
                }

                valideControlPoints.Add(bestControlPoint);
          }
      }

      // Find new spline
      int randomIndex = Random.Range(0, valideControlPoints.Count);
      CurvySplineSegment controlPoint = valideControlPoints[randomIndex];
 
      if (controlPoint != e.ControlPoint)
      {          
          e.Follow(controlPoint); // Follow the new spline

          // Set the controller to use the new spline          
          Controller.Spline = e.Spline;
          Controller.RelativePosition = e.TF;
       }
}  

My goal with the code is to check if the path will be smooth enough to validate a new spline. Additionnaly if the current spline is closed or the current control point is not the last point, the spline itself is added to the pool to be randomized later as the next spline. But if it's not possible to continue on the current spline because it's the last point, I make sure that the controller will choose another spline even if it's not smooth.
Reply


Messages In This Thread
Connections/Controller issue - by lllApOlll - 03-05-2018, 04:03 PM
RE: Connections/Controller issue - by _Aka_ - 03-05-2018, 04:41 PM
RE: Connections/Controller issue - by lllApOlll - 03-05-2018, 05:19 PM
RE: Connections/Controller issue - by _Aka_ - 03-05-2018, 07:30 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Rasterized Path Range issue proton 7 26 04-30-2024, 11:17 AM
Last Post: _Aka_
  Set Volume to the Volume Controller at Runtime pako88 2 10 04-08-2024, 03:26 PM
Last Post: _Aka_
  Connections Problem Juton 3 16 03-06-2024, 10:41 AM
Last Post: _Aka_
  Add noise to spline controller movement DekoGames 2 10 02-06-2024, 01:28 PM
Last Post: DekoGames

Forum Jump: