Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Updating old movement code
#1
Hi! I am updating curvy from 2.0.4 to 7.0.0 and have some old code to move player along the spline. The most part of update went surprisingly well, but there are some places that are not that easy to rewrite:



1.
Code:
Vector3 pos = spline.MoveByLengthFast(ref tf, ref direction, spd * Time.deltaTime, CurvyClamping.Clamp);



Unfortunately i can not find any new method like "MoveByLengthFast" to get new position for my player. Was it completly removed? Any new method like this?

2. I made some art of "tunnels" with splines, that can have forks with multiple spline segments connected to one point. My code to choose what path to take was like that:




Quote:CurvySplineMoveEventArgs last_curvy_event = null;

void onControlPointReachedEvent(CurvySplineMoveEventArgs e) {
    last_curvy_event = e;
}
foreach (CurvySplineSegment cp in e.ControlPoint.ConnectedControlPoints) {...}


But e.ControlPoint has no connected control points anymore. How do i get them now?


(onControlPointReachedEvent seems to by moved into SplineController, probably it is easy to rewrite it from spline)

3. What about old splines made with old curvy version? Well on the first look right seem to be OK. I can edit them as normal in Unity. Is it safe to leave them for new curvy version, or do i need recreate them from scratch?

[Image: f70a2711b7.jpg]
Reply
#2
Hi,

Here is some context, and after that I answer directly your questions:

That's some very old Curvy version. If not done already, make sure you read the release notes so you don't miss any new feature.

After aquiring Curvy on 2018, one of the things I worked on is to simplify the API. There was too many public methods which were basically a one liner calling another public method. I removed (and still removing) a lot of those methods to make the API as small and easy to use as possible.

Before releasing any breaking change in Curvy, I mark the API method that will change as Obsolete, while providing the new alternative. The Obsolete tag displays a compiler warning when compiling the code, and often I add to it a custom message saying what method to use instead. So for someone who updates regularly, and acts accordingly when seeing a compiler warning from Curvy, the upgrade is done smoothly. But for someone who had not upgraded for a long time, then this process becomes problematic. Ideally, the Unity asset store would allow owners of a specific asset to get all the older updates, so you could upgrade easily and gradually between consecutive versions, but this is unfortunately not the case.

Now the answers:

  1. MoveByLengthFast and other move methods were reworked and moved to the SplineController class. The closest thing you can find in recent versions is SplineController.SimulateAdvance (if you don't need events to be triggered while moving). Otherwise look at SplineController.Advance.
    If neither of those help, I am sending you the old implementation of MoveByLengthFast, but it will not compile without modifications.
  2. e.ControlPoint.Connection.OtherControlPoints
  3. I am not aware of any change in the spline's data that is not backward compatible. Let me know if you find such thing.
Did all this help?
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#3
(08-17-2020, 02:44 PM)_Aka_ Wrote: ...
Hi, thank you for a quick response. Well yes, my project development lasts a little bit longer as i wanted. Probably it was unity 4.3 -> 5.6 -> 2018.2 -> 2019.4 updates. And Curvy 2.0.4 seems to work until 2018.2 pretty well, so i just used the old version.

1. Thank you, yep after some adjustments the old code almost works again. My old code expects splines in relative mode, but old function "MoveByLengthFast" ensures player moves same speed on long and short segments. But with this "hack" my code seems to work well in relative mode but moving in world unity. I basically switching to Abs-mode for short time:

Code:
splineController.MoveMode = CurvyController.MoveModeEnum.AbsolutePrecise;
splineController.DoAdvance(spd, Time.deltaTime);
splineController.MoveMode = CurvyController.MoveModeEnum.Relative;
I hope this is OK and does not ruin anything inside of Curvy. (i can not just switch SplineController to absolute mode, would be nice but breaks old code).

2. Yes, it works. Thank you!

3. It seems to work well with splines created in 2.0.4. No problems was found.

So thank you for your help.

[Image: giphy.gif]

P.S. It would be probably much nicer just rewrite it all from scratch, new API looks easier indeed, but ... well i did not planned any curvy-programming. I just want to update to unity 2019 Smile
Reply
#4
1. Should not break anything as far as I know

And I agree with you, no need to use the updated API as long as the old code works.

Good luck with your project, and feel free to share it with me or on the forum once ready.
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
  Movement on Curvy with MouseWheel staticdreams 1 309 06-22-2020, 12:13 PM
Last Post: _Aka_
  Creting SplineControllers thru code generating errors curvyuser007 7 955 06-07-2020, 04:19 PM
Last Post: curvyuser007
  Choppy movement Lasercat69 3 1,825 04-17-2020, 07:18 PM
Last Post: _Aka_
  Rigidbody or Transform Movement ATHellboy 10 2,744 02-04-2020, 08:37 PM
Last Post: _Aka_

Forum Jump: