# How to move part along a line?

Hi i want to make a system where i move a part back depending on how far another part is back along an imaginary line: like this

make the red part move with the blue one one a single axis

( im not looking for welds or doing cframe = bluepartcframe * offset i need this calculated in real time on a 0-1 howfaritmovedbackalpha)

(click on imagine if it doesnt work)

This sound like something you can do with CFrame:Lerp() (Aka. Linear interpolation ) where it uses a % from a Start and EndCFrame and moves that precentage (Ex: 50% would be in the middle of those 2 CFrames )

This sounds like a starting point that could maybe help you. But more context would help.

Is it always a line or are you planning for it to have curves?

thats what i was doing, but i mean i need to calculate how far it moved back after all and then positon it correctly and make sure its not extending past the lines edges and have this work regardless how the line is angled etc and detect if it even moved in the right direction because magnitude could go into negative direction

both, sometimes lines and rarely curves, by curves i mean you know sniper bolts, you have to angle them upwards to move them back typa song if you know what im saying

The best way to do this is to have your path be some function which has an arc length parameterization, which means you give it a distance and it gives you a point that’s that far along the path. Then you can always get your point X distance behind another. Some curves have this property by default, but you could always convert any curve that doesn’t into a list of many lines (a spline). The comprehensive explanation is here: The Continuity of Splines - YouTube

thanks for the help but im gonna be totally real w u i got no clue what you mean, what you mention is beyond my knowledge, i might be able to understand it with a code sample or something

If you did this:

``````pos = Vector3.new(1, 2, 3).Unit * X
``````

Then pos is a curve (Yeah its straight but we count that) which is arclength parameterized by X. Every time you increase X by 1, the position moves 1 unit further. So if you wanted the point 1 unit behind another, you’d just say the first point has X = 10 and the point 1 unit behind it has X = 9.

i originally had this planned for VR sniper bolts/ pistol slides, my thought was to use magnitude on a normalized 0-1 lerp from start to endposition but this might even be better. so as i understand it you mean to turn the line or path of the gun bolt into individual points or splines and then calculate how far the hand is say to see which position i am on the path, is that correct? now my questions are how would i accurately ‘map out’ say a sniper bolt path:

and how could i detect if the hand has moved back in the right direction relative to the bolt and how far, and then calculate the position on the path