Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Orientation in 2D
#11
I found one of the big wrenches that was mucking up things for me. I'm drawing and redrawing tracks at runtime, and I use Spline.Clear() to clear out the old control points before spawning new one. But I also had Use Pooling checked true for the spline, which is the default. So it seems like when the control points are pulled from the pool, their rotations are not being reset. That's how I could draw and redraw the same track and get different orientation results.

I unchecked Use Pooling, and now I'm working with shiny new control points.
Reply
#12
(07-29-2018, 09:31 PM)Livealot Wrote: I learned that you can't instantiate and rotate a control point in the same step since there are some functions (GetOrientationFast) that needs the cache from the spline.
Since you are using Curvy 2.3.0, I am getting back to that quote. When you say "I learned", do you mean you read this on the forum, or you found an issue in your current version? If the latter, I am interested in more details.

(07-30-2018, 11:27 PM)Livealot Wrote: So it seems like when the control points are pulled from the pool, their rotations are not being reset.
You are right. I will modify this in the next version, so that pooled control points will have default transform.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#13
GetOrientationFast will throw an IndexError if its called prior to refreshing the spline after creating new control points. Refreshing the spline is automatic when you use spline.Add and when you use spline.InsertAfter with skiprefreshingandevents set to false. I was using spline.InsertAfter with skiprefreshingandevents set to true, which I think I cut and paste from the InfiniteTrack example. Hopefully that's more clear.

I've continued to make progress in 2D and now have it working reliably for a whopping 62.5% of my 2D scenarios (see below). So I'm hoping you might have a hunch on where to look to solve the rest.

I gave up on the Static orientation approach and returned to using the dynamic mode and have discovered that the 2D orientation "bug" depends on the starting and ending orientation of the spline. If the start/end is a "valid" combination, the 2D sprite stays to the same side of the spline and on the 2D plane, regardless of the path shape in between the start and end. But if the start/end is an "invalid" combination, the sprite will "get skinny" at some point along the spline since the orientation at some control points leave the 2D plane.

Starting Direction: West
     Valid Ending: West, 
     Invalid Ending : North, East, South 

Starting Direction: North, East, or South
     Valid Ending: North, East, South 
     Invalid Ending : West

To say a different way, if the initial control points are heading to the left in 2D, the final control points MUST head to the left to maintain the proper 2D orientation. If the initial control points start heading up, down, or right, the proper 2D orientation is maintained UNLESS the final control points head to the left. The shape/complexity of the spline in the middle does not seem to matter at all.

So this helps narrow it down, but I still haven't found the fix although I explored some hunches:
  •   getOrthoUp0INTERNAL() uses a static Vector3.up reference which may not be appropriate for 2D but I wasn't able to change that in a way that yielded better results
  • Auto End Tangents toggling on and off didn't seem to have an impact
  • the end of ProcessDirtyCheckpoints for !closed splines does something but I couldn't figure that one out
Any ideas are welcome, and thanks again for all the pointers so far.
Reply
#14
(08-01-2018, 12:30 AM)Livealot Wrote: Hopefully that's more clear.
Absolutely. Thanks for the details.

(08-01-2018, 12:30 AM)Livealot Wrote: The shape/complexity of the spline in the middle does not seem to matter at all.
When using dynamic orientation, the orientation is deduced from the Orientation Anchors rotations (in addition to swirling). By default, the first and last CPs are Orientation Anchors. Then users can choose to set specific CPs as Orientation Anchor.

(08-01-2018, 12:30 AM)Livealot Wrote: getOrthoUp0INTERNAL() uses a static Vector3.up reference which may not be appropriate for 2D but I wasn't able to change that in a way that yielded better results
The Vector3.up is multiplied by the CPs rotation, so chaging the rotation should do the trick, or am I missing something?

(08-01-2018, 12:30 AM)Livealot Wrote: Auto End Tangents toggling on and off didn't seem to have an impact
This setting is irrelevant to your current concerns. This setting is used by spline interpolation modes that need at least 4 CPs to work. It is used to decide if the spline should "duplicate" behind the scenes the first and last CP to get the sufficient number of CPs.

(08-01-2018, 12:30 AM)Livealot Wrote: The end of ProcessDirtyCheckpoints for !closed splines does something but I couldn't figure that one out
If you mean this code
Code:
// Handle very last CP
if (!Closed)
{
  CurvySplineSegment beforLastVisibleCp = GetPreviousControlPoint(LastVisibleControlPoint);
  LastVisibleControlPoint.ApproximationUp[0] = beforLastVisibleCp.ApproximationUp[beforLastVisibleCp.CacheSize];
}
This gets the last up of the last segment, and set it as the first (and unique) up of the last CP (wich is not a segment, since the spline is open).
About the CPs visibility, the default behavior (splines having Auto End Tangents to true) yield splines with all their control points visible.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#15
Great news. I now have Curvy working in 100% of my 2D use cases.

Your initial suggestion to just flip the ending CP was ultimately correct. It didn't seem correct at first due to the pooling issue and because flipping is scenario dependent. And then once the pooling issue was addressed, I was already deep in the muck of using interim control points as orientation anchors and procedurally setting their orientations, which caused as many problems as they solved. Backing those things out, using Dynamic Orientation, and finding out WHEN to flip the ending CP was the ultimate answer.

Here it is for anyone who is working in 2D

Code:
public CurvySpline m_TrackSpline;

private List<Vector3> m_ControlPoints = new List<Vector3>();

private void Construct2DSpline() {
//clear previous track
m_TrackSpline.Clear();
m_ControlPoints.Clear();
//do not use pooling until Curvy is updated to refresh the orientation of pooled objects

//fill a list of 2D control point locations specific to your scenario/game

m_TrackSpline.Add(m_ControlPoints.ToArray());

//compare orientation of starting and ending control point to flip ending cp when appropriate to maintain 2D orientation
Vector3 startEuler = m_TrackSpline.ControlPointsList[0].GetOrientationFast(0f).eulerAngles;
Quaternion endRotation = m_TrackSpline.ControlPointsList[m_TrackSpline.ControlPointCount - 1].GetOrientationFast(0f);
Vector3 endEuler = endRotation.eulerAngles;

bool bShouldFlip = false;
if (startEuler.y > 269f) {
if (endEuler.y < 269f) {
bShouldFlip = true;
}
}
else if (endEuler.y > 269f) {
bShouldFlip = true;
}

if (bShouldFlip) {
Quaternion finalTwist = endRotation * Quaternion.Euler(180f, 0f, 0f);
m_TrackSpline.ControlPointsList[m_TrackSpline.ControlPointCount - 1].SetRotation(finalTwist);
}
}

Similar logic might make for a good bool toggle companion to RestrictTo2D

Thanks Aka for all your help and patience!!!
Reply
#16
Great news, happy to see that you reached your objective.
When your game will be publicly announced, I would appreciate if you send a link so I can see the final result.
And thanks for your feedback. Such feedback helps me improving Curvy.
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
  Shapes points orientation itsGama 3 8 01-18-2023, 02:51 PM
Last Post: _Aka_
  2d - orientation looping_co 1 5 09-01-2022, 04:17 PM
Last Post: _Aka_
  Spline controller orientation itsGama 4 30 01-24-2022, 06:38 PM
Last Post: _Aka_
  Regarding static orientation mydayz 10 287 12-05-2021, 01:25 PM
Last Post: _Aka_

Forum Jump: