Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Solved] SplineController skips on CurvySpline.ControlPoints[0].Delete()
I have a SplineController script attached to an object, and the object travels along a spline perfectly.

However, when I delete a point from the spline, the object jumps forward:

The object is already between points 5 and 6, far ahead of the control point in question.

If it helps, my goal is for the SplineController object to travel endlessly along a spline (typical endless runner). Periodically, I remove a control point from the beginning of the spline and add it to the end.

Yeah, this is glitch that will be handled in the 2.0.5 update. AdaptOnChange does not handle deletion of CP's properly.

To help you understand what's going on:

The SplineController keeps a TF "pointer" internally. By adding/removing CPs the same TF would result in a different position and this causes the jumps you're noticing.

Note that even after 2.0.5 AdaptOnChange can't handle multiple actions in a single frame, so the easiest way is to handle it by yourself, because you know where you delete/add what. Two ways to handle this:

1.) Use SplineController.Spline.TFToSegment(SplineController.RelativePosition) to get the current segment and local position within. Then add/remove CP's at will (not the one you're over, but anything else is fine), then set the controller to the new TF (shortened): RelativePosition=seg.LocalFToTF(localF)
2.) Store the distance from start (SplineController.AbsolutePosition). Adding CP's in front of the current position is fine, if you remove CP's behind it, subtract the length of the deleted segment from the stored distance. After done, set SplineController.AbsoluteDistance to your stored value.

I'd prefer the former solution because of better accuracy.
Thanks Jake, it worked. With the first method, the SplineController's position doesn't change at all.

However, I noticed that the SplineController's rotation does change after removing and adding a control point (position remains identical, and spline looks visually identical). Is this a bug?

It's a moot point for me now, because another issue revealed itself: When I remove a control point, the mesh changes, and the texture shifts as a result (both managed by Curvy Generator). This obviously isn't a bug, but it means I probably need to add/remove entire splines rather than segments. Does that sound like the right approach?

By default orientation is calculated automatically using an enhanced Parallel Transport Frame (PTF) algorithm. That's why it changes slightly when you add/remove CP's. To prevent that flag some CP's (at least one before your visible "track", one behind) as OrientationAnchors. PTF then takes this anchors as start/end conditions, thus calculating only a smooth path between those anchors. Just play with anchors in the editor to see it at work and get the idea.

Note that when you enable an anchor, the current orientation (usually auto-calculated) is set, but you can rotate the transform to alter that.

Also note that this has a nice performance side effect, because when you change the spline, only orientation of the affected anchor group (segments between two anchors) needs to be recalculated. Say we have a spline with 1000 CP's. When you change the first CP, whole orientation needs to be recalculated. If you set CP 500 to be an anchor group, only the first 500 CP need an orientation update. But that's just spline refreshment magic happening behind the scenes...
Makes sense, and it worked. Thanks Jake! You've elucidated the subject, so I'll mark this as solved.

Of course, I might've ended up with an XY problem: Every time I remove a point, the Curvy Generator-managed mesh around the spline changes, and the texture shifts. I don't think this is preventable, and the obvious solution is to use two splines, but is there anything else I can do? Any Curvy best practices for this? Should I post this as a separate thread?
In our dynamic road example (coming with 2.0.5) we set the CG's texture offset manually before rebuilding the mesh. Works like a charm. Hopefully will ship this week (yes, saying this for weeks Big Grin but now it needs to ship...)
Fantastic. I'll be waiting for that; the examples have thus far been very helpful.

Possibly Related Threads…
Thread Author Replies Views Last Post
Thumbs Up Can't delete connection lacota 3 6 03-16-2024, 11:34 AM
Last Post: _Aka_
  I have a question about curvySpline haifeng.huang 12 32 07-14-2023, 09:34 AM
Last Post: _Aka_
Thumbs Up Assembly Definitions (Solved) lacota 3 6 06-01-2023, 11:04 AM
Last Post: _Aka_
  "Deadloop in CurvySPline.Refresh" spam Valkymaera 3 11 05-30-2023, 10:56 AM
Last Post: _Aka_

Forum Jump: