I’m making an object which the player controls it by adding relative location.
What a want to do: When this object arrive some distance (length between Character and the object), they will not be possible to go any further, just to return, and keep in that radius without going away.
Just need clarification on something. Are you trying to keep the object within some distance of the character? Or are you trying to keep the character within some distance of the object?
If you want to keep something within a certain radius of something else, you can try doing this. Say we want to keep “B”, within some distance “r”, of “A”.
Get the vector, let’s call it “U”, from the A to the location where you are trying to move B.
Get the size(length) of U and check to see if it’s greater than r.
If it is greater than r, don’t move B in that direction.
If B somehow ends up outside of the radius, just normalize U, then multiply it by r. Set this vector as B’s relative location from A.
This is also assumes that B is also attached to A. That way B moves with A.