Hi everyone!
The title of this post may sound a bit vague so let me explain: how can I make a model\part grow in length and curve towards a certain position(for example the player’s mouse)?
Let me link some references:
Reference 1: As you can see in the gif, the white part (and the rainbow ones too, which rotate around it somehow) seems to grow and move towards the mouse position. And no, it’s not using beams, you can clearly see it’s using cylinders to create the segments of the model, like in this pic.
Reference 2: this one is a lot more similar to what i’m trying to achieve. It starts from a point and the model keeps “growing” towards the player’s mouse position.
Keep in mind I’m not asking for someone to code this for me, but rather to explain the logic and\or math behind these effects.
If I had to guess how this is done, I’d say it’s CFrame math and Tweening, to simulate the growth effect of each segment in the second reference.
Both of these have some underlying 3D curve or spline that is defining the shape. This can be any 3D curve but it helps a lot if it has a length parameterization, meaning its possible to input a length and get a point on the curve. Beziers do not have this property. To learn more about curves I recommend this video: The Beauty of Bézier Curves - YouTube
As for the growing, they are just gradually filling up the curve over time. The simplest way would be to add one known-length segment every unit time, ie add one 10 unit long branch every half a second. The end point of each segment will be the start point of the next segment. This is why a length parameterization is useful. Without one, you will be able to control the total time it takes to fully grow the curve, but not the speed at any given point or how long each step segment will be, and will have to calculate it.
I suspected it was something that had to do with Bezier or Splines - I did actually watch the video you linked and funnily enough the creator of that same video posted another video about Splines last week lol!
I thought they did have length parameterization, that’s odd. Are splines a better pick, if so? I’m not familiar with those but I assume they probably do have that property if you say so.
Splines are the class of lines made up of smaller segments of curves such as cubic beziers. Bezier splines do not have an analytic length parameterization, but you can approximate it very closely as that video shows. The other kind of spline that I tend to use is Hermite Splines, because you specify a start and end point, and start and end velocity for each segment. This is much more useful for projectiles than cubic bezier, it just depends on your application.