How would I go along scripting a part that would have to glide between two points? Not exactly a tween but rather how would I make it so sliding it left would bring it closer to A and sliding it right would be closer to B and prevent it from leaving those two points?
What you are looking for is a lerp.
suppose point C must be between point A and B, you can do A.CFrame:Lerp(B.CFrame,percent) where percent is a number between 0 and 1 specifying how close the part is to B where 1 means at B and 0 means at A
lerp also works for vector3
Oh that’s exactly what I need, thank you!
I know the post is marked solved, but you didn’t give many details about exactly how you want this movement to work in your game.
Is this for a platform that players stand on? If that’s the case then you don’t want to use a CFrame because that’s not a ‘physics’ movement and the player will slide off as the Part moves.
Is it a Part that’s moving from 2 fixed points or do the Positions of the points change during gameplay?
A Prismatic Constraint could help you out here to move between 2 points that don’t change.
A DragDetector could work without even having to code anything. A player could just use the mouse or touchscreen input to drag the Part from A to B.
Sorry that I wasn’t very clear, but it was just regarding scripting an anchored part to slide between two fixed points and being able to stop it without needing a tween, so the lerp was what I needed. But I do appreciate the other options
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
