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
#2
Hi,
The picture is missing. So I will answer blindly. If the answer is not correct, repost the picture and I will give another answer accordingly.

Does your controller have Clamping set to Loop. If yes, try to set it to Clamp and see if it behaves like you want.
Also, keep in mind that, in the last line of your code, you can set you can set RelativePosition to whatever value that suits you.
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply
#3
I updated the image, it should be easier to understand now.

But I think I found the issue, it's here :
Code:
if (e.Spline.IsClosed || !e.ControlPoint.IsLastControlPoint) // Can continue on the same spline
   {        
        valideControlPoints.Add(e.ControlPoint); // Add current spline      
   }

That should be like this :
Code:
if (e.Spline.IsClosed || (e.ControlPoint.IsLastControlPoint && Controller.Direction == -1) || (e.ControlPoint.IsFirstControlPoint && Controller.Direction == 1)) // Can continue on the same spline
        {
            valideControlPoints.Add(e.ControlPoint); // Add current spline      
        }

It appears that my code added the current spline even if it was not valide and that led to the bug. 
If I undestand correctly, since my code allowed the current spline to be continued, the contoller just got back to the start of the spline and given that the start point had connection, the code started again and choose the main spline, so I thought the controller teleported.
Reply
#4
(03-05-2018, 05:19 PM)lllApOlll Wrote: If I undestand correctly, since my code allowed the current spline to be continued, the contoller just got back to the start of the spline and given that the start point had connection, the code started again and choose the main spline, so I thought the controller teleported.

From reading the code, your explanation seems good. Case solved then Smile
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Procedural Connections Janooba 3 7 10-23-2024, 02:53 PM
Last Post: _Aka_
  Can't set CG Path Controller j95677 4 22 10-04-2024, 06:55 PM
Last Post: j95677
  How to use CG Volume Controller j95677 5 12 07-17-2024, 07:15 PM
Last Post: j95677
  Connections doesn't work in split scenes nehvaleem 4 10 05-29-2024, 07:31 AM
Last Post: _Aka_

Forum Jump: