Dynamically Move Object Along Spline?

I want to create a spline (or whatever method works best) to enable the player to click and drag an object along it back and forth. The start and end of the spline would restrict the movement so it cannot go beyond either points but it must also be restricted to the spline in other axis as well (the player not being able to move it side to side, only forward and backward on the spline).

How can I achieve this? And if not with a spline, how else?
This is inside a BP, and for VR - where the player can grip the bolt and pull it back, then release to have it snap back. If and when the bolt reaches a certain point, a new bullet would be loaded in. I can do all of this, I just don’t know how to set up the restricted movements controlled by the player along a spline.

Any image references would be greatly appreciated!
I can only find resources by googling that allow for AI to move along splines, etc. But nothing that movable by the player via click-drag or physical grab > move.

Thanks

If it’s a straight line, I’d avoid a spline and just clamp the relative location to the desired value. Or you could map range a timeline to have a nice smooth movement - this is probable the best method.

In case you really do need a spline because the movement path is a curve, for example, have a look here - the graph shows how to get movement along the spline:

A timeline would work if possible but how exactly do I do it in a way that allows the player to manipulate the value? I would need to determine location A and location B and when the motion controller moves along the X axis from A to B, the float value in the timeline would change accordingly.

Not really, you use the Timeline to output a value from 0 to 1, and use that value as alpha to lerp between 2 vector locations:

You can use the same technique with a spline, by the way. Where A is a float 0 and B is float (splineLength).

1 Like