Replicating CM2's SmoothPath in CM3's Splines

Hey there,

I was highly working and dependent on Cinemachine 2’s CinemachineSmoothPath, I liked it very much; it was easy to set and was highly buttery smooth. Although I like CM3 and would like to use it, I have difficulty setting up the same buttery smooth feeling in CM3 with Unity Splines.

One of the biggest issues I am having is that Unity spline’s behavior is rather “abnormal” when the cart is reaching a knot, compared to CM2’s CinemachineSmoothPath.

Once the cart reaches a knot, it kinda “snaps” to the rotation of the next knot, yielding a static, mechanical behavior that is exceptionally visible.

I am using the spline paths in “Auto” mode, believing this is the closest to the behavior of Cinemachine Smooth Path. I don’t want to manually set the rotations via Bezier and Linear isn’t what I am looking for – thats for sure.

I want a fully smooth, extremely buttery-smooth, CinemachineSmoothPath, just like in the CM2.

SmoothPath was a Bezier with the tangents of each knot set to point in exactly opposite directions and to have the same magnitude. That’s what stops the snap.

So: for each knot

  • Tangents are the same magnitude
  • Tangents are colinear, pointing in opposite directions

Thanks for the insight! So via code or manually, how can I achieve that? Can you explain, please?

Seems to me that you just want to use Mirrored tangent mode on the knots:

9929499--1436670--upload_2024-7-8_13-10-34.png

Problem persists regardless of the Bezier “Mirrored” mode and Auto “Mirrored” mode.

You can clearly tell the camera “somehow” snaps to an angle.

Below is the time-codes for what I am trying to point out by saying “snaps”.

0.03, 0.05, 0.11, 0.16

CinemachineSmoothPath wasn’t like this.

Please see the screenshot below to tell me if thats good or not or anything, really

I can’t tell offhand what’s happening. Would you be willing to send me the scene?

Sure.

I excluded the “HDRP Sample Scene” assets, if you create a project with it on your end, it should do good.

9929601–1436694–snappingsplinescene.unitypackage (121 KB)

It seems that you’ve set the rotations of the knots in your spline. Is that the case? If so, how did you do that?

For a smooth path, you should not be setting the rotations of the knots. The CinemachineSmoothPath is smooth because it relies exclusively on the position and tangents of the knots. To replicate that, don’t manipulate the rotations of the knots because it will be difficult to preserve smoothness. You can add a CinemachineSplineRoll behaviour to the spline to introduce roll if you need it.

I’m also noticing that not all your tangents are correctly mirrored with the same In and Out magnitudes. This can create discontinuities in your path. Check them all carefully and make sure that the In and Out magnitudes match (maybe you can write a little script to iterate and make corrections)

9929781--1436721--upload_2024-7-8_16-15-51.png

Zeroing the rotation yields the paths surface being broken like this(now they all look the 0,0,0 direction);

I was heavily utilizing the CinemachineSmoothPath’s Roll, and I will be using the CinemachineSplineRoll, that’s for sure. Great UX improvements on the Cinemachine! That’s perfect.

Setting Beziers to mirrored and having the same magnitude In and Out actually helped a bit. But it still feels like rather “snapping”. Attaching another video with timestamps;

0.33, you can feel like as if it hits something and slowly rotates
0.35, it kinda hits something and stops
0.41, same, it feels like it hits something
0.46, as well
0.49

I feel like I am so close, just one more thing and this will be fixed :slight_smile:
Thank you very much for your help this far

Oopsie woopsie, forgot to share the link, this is the link to the video;

Looking only at the 0:33 snap. It corresponds to knot 1 on the spline (in the scene that I have). Knot 1 looks like this:

9930873--1437042--upload_2024-7-9_7-43-9.png

Notice that In and Out are very slightly different. When I click on Bezier it looks like this:

9930873--1437045--upload_2024-7-9_7-44-21.png

So it seems that really, under the hood, it’s not quite mirrored. This may be a bug in Splines. I’ll raise it with the splines team. In the meantime, let’s fix it:

9930873--1437048--upload_2024-7-9_7-45-33.png

Now let’s look at the tangent itself. You can see that it’s not quite symmetric, and will probably introduce a little wobble (a smooth wobble, but a wobble nonetheless):

Let’s fix it:

Now when I play, it’s smooth in that section. You’re going to have to painstakingly adjust your knots to iron out the kinks.

Cinemachine’s SmoothPath did this automatically, and it’s a little disappointing that spline’s Auto mode doesn’t quite meet that standard. Under the hood, SmoothPath was just a bunch of beziers with the tangents tuned appropriately. One could, I suppose, write a little “smoothify” script to automate this for a spline.

This thread might be of interest to you. It’s an alternative way to make a curated dolly shot, without having to mess with spline rotations. Feature available in CM 3.1.1.

Man, you developed a new component out of the thin air because someone was struggling with it. You are being very helpful to me and folks over here, you rock! I never felt like my ass is covered by Unity at any point of my past 8 years of life within Unity.

However, I did as how you suggested exactly but there is some “misaligned” behaviour under the hood – thats for sure. Thanks for forwarding this case to the Splines team. One note that I believe this may yield other problems on the Cinemachine 2 to Cinemachine 3 Upgrader, especially on projects depending to the “CinemachineSmoothPath”.

Snapping still occurs, please see the scene file I attached below. Cherry-picking Dolly Cart and Spline should be good for you.

Would you be so kind to help me with some algorithm or really anything to put me in a direction. If I understand what needs to be done to “smoothify” the Spline, then I might be able to create, and/or work on a solution to “smoothify” the spline.

Keep in mind that, you, ROCK!

9931056–1437096–AllBezierMirroredStillSnapping.unitypackage (121 KB)

ok, so I checked with the Spline team and it turns out that Auto mode is not designed to produce splines that are suitable for use as camera paths. I had been under the impression that it was, so now CM3 is left without an out-of-the-box replacement for SmoothPaths. Merde.

It’s quite tricky to tune the tangents by hand. Not only do they have to be mirrored and oriented exactly right, they also have to have exactly the right length, or there could be jerkiness in the final camera movement. That’s why you’re having issues with your path.

I suppose the simplest way forward short-term is to do as I suggested: write a little script to auto-update the tangents whenever the knots change. The algorithm CM2 used to auto-set the tangents considered the spline as a whole and computed the appropriate values.

I’ve adapted the code from CM2 and packaged it in a stand-alone behaviour that you can add to your spline. With AutoSmooth enabled, It keeps track of the spline’s knot positions, and triggers an auto-smooth whenever something changes, so you get pretty much the behaviour of CM2’s SmoothPath.

Whenever you change a knot position, it will automatically adjust the tangents and other settings in the knots. It is Undo-friendly.

One thing to note: it’s only tracking knot position, so if if you manually adjust a tangent or some other setting in a knot, it will temporarily let you do that, but those changes will be overwritten the next time smoothing is triggered. If that behaviour is a problem, it should be fairly easy to change it and have it track the entire knot.

Please give it a spin and let me know if it does the job for you.

EDIT: find the corrected version of the script here: Replicating CM2's SmoothPath in CM3's Splines - #23 by Gregoryl.

Wow. My initial test resulted that this eliminates all the things I declare “issue” in it.

This is a very good starting point I guess, but introducing CinemachineSplineRoll makes the issue “kinda” re-occur.

I suppose thats normal because you didn’t really thought of it, is it possible to implement CinemachineSplineRoll in this?

One point that it adds a new knot to the end of the spline, I will check it later

Are you using CM 3.1.1?

That should not be. The presence of SplineRoll should not interfere. Can you send me a scene, or show what you mean?

EDIT: ok, I think I understand. The PathSmoother does not smooth the roll values. That’s true.

The solution is to add easing to CinemachineSplineRoll. You’ll have to wait for CM 3.1.2 for that. Huge thanks to you for bringing these issues to our attention.

9932952--1437627--upload_2024-7-10_8-3-57.png