Adding 3D curves to Unity

I’ve been using a lot of curves lately and wondering why they aren’t officially implemented in Unity. AnimationCurves are great and very useful but I’m talking about scene space 3D curves.

I added a feedback entry here: https://feedback.unity3d.com/suggestions/simple-3d-curve-generation

Would love to hear other ideas related to this potential feature.

They are supported in the editor of course.

But assuming you mean during runtime:
So I believe a small piece of code and line or trail renderer is all you require. Curves come in many forms but I think bezier is the most common kind.

If it were going to be added as a native feature it would not be trivial because everyone needs different lines. Some people want tubes, some people need them antialiased and others need a minimum thickness.

This topic doesn’t belong in scripting because it’s a feature request. I’ve moved it to general.

I haven’t found them in the editor at all except for AnimationCurves. Is there a way to bring in a curve and adjust the handles, etc? But yes, I would also like the ability to use them at runtime in C#.

I agree that it wouldn’t be trivial to add them, but I think the functionality could be fairly streamlined to allow for easy manipulation of the curves. Bezier curves with auto-handles generated would probably be best, and you would only need to worry about adjusted the handles if you needed finer control over them.

Constructing them and using them in this way would be ideal:

Vector3[] points = new Vector3[] {point1, point2, point3];
Curve myCurve = new Curve(points);
Vector3 pointOnCurve = myCurve.Evaluate(.2f);

Actually, it would be relatively trivial to add them. All you really need is a series of points, variables to determine smoothing handles, and the necessary calculus for drawing the resulting lines in the editor.

Points are simple. You just need individual 3D coordinates. That is built into the default transform component already. You could just use empty game objects as the basis for your points, or cook up a customized version. Either way it’s just points in 3D space. Three floats per point is all you really need.

The handles are the tough part. Defining their relationship to their individual points, as well as handles on the opposite side of a point, would be considerably more difficult. It’s workable, but you would have to do some decent interface coding for them. Interface drawing is considerably easier. They basically just need to be a straight line connecting the handle to its associated point. Easy-peasy.

Drawing the curves is where the calculus comes in, and it would be considerably more complicated. Have fun with that. I’m not a mathematician, I can’t really help you with drawing that complex, but it does ultimately boil down to math. Thankfully, there are all sorts of interface drawing tools for an in-editor widget such as this, but you will still have to crunch some fairly serious 3D math.

I’m assuming you would want to use all of this to visualize the animation curves in 3D space, right? Because there will be no functional difference between what I’m describing here, and the 2D animation curves that you mention. At the end of the day, the one would effortlessly translate into the other. The only real difference is the visualization, being able to draw the path of the object in the editor.

Yeah, I found some code online that helps with calculating the curves between points but I ended up going with an Asset Store solution instead. There is a plugin called “Curvy” on there that does a great job. I guess I’m just wondering why this type of thing isn’t built into Unity. It might even be worth it to Unity to hire that asset author.

I can think of all sorts of uses for creating curves through code/editor. One of the main ones would be paths for objects that aren’t just linear, point A to point B type of movements. Particle paths, geometry extrusions… pretty much anywhere they are already useful in DCC tools such as Maya. I know the coding might be tough under the hood but that’s where Unity shines, so I figured it could be a good feature request. If you agree then please feel free to +1 my feedback suggestion: https://feedback.unity3d.com/suggestions/simple-3d-curve-generation

Just grab one of the assets from the store that handles it. Here’s a free one.

Some of the paid ones are fantastic too.

Unity could implement it themselves of course but we all know how long it takes them to do anything.

The coding would only be tough for the visualization. The rest is cake. At the end of the day, the data you would actually be creating would simply be animation curves for the X, Y, and Z values of a game object’s transform component. The only real challenge is doing the math necessary to take those values, and render them as a single line in 3D space. The handles would require a little coding for the various features, but aside from that they wouldn’t be that difficult, as they only require rendering straight lines and manipulating object transforms as you normally would.