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
  Add noise to spline controller movement DekoGames 2 10 02-06-2024, 01:28 PM
Last Post: DekoGames
Question Setting instantiated object to spline, then starting movement? _RicO 3 9 06-28-2023, 06:01 PM
Last Post: _Aka_
  Permission to publish custom CGModule source code? Apelsin 6 9,422 09-15-2022, 08:53 PM
Last Post: Josaf Tom
  How can I set the generator to stop updating? Chanon 3 19 09-08-2022, 02:54 PM
Last Post: _Aka_

Forum Jump: