- Inside Slide(), you could clamp the transformed position such that it never goes outside the range of [startPos.x, offsetDistance.x].
- Instead of accumulating translations in _transform to move your object, you could model the movement as an oscillating function, and just sample the function each frame to get the object's position. This would also have the benefit of removing the possibility of your object's position drifting over time from accumulated floating point rounding.
- Wow, I didn't even think of that! I'll look into Mathf.Clamp and see if that works!
- By "sample the function", do you mean to increment the localPosition.x value 'manually'?
However, your startPos isn't set. Could it be that your cursor goes to 0/0 and slides around there?
I tried setting startPos to the transform's local position since that where I want the initial position to be, but that didn't seem to change anything.
Btw, thanks so much for helping me out with this!