How to not make part go outside a distance

How would I make it where if the cursor is farther than a max a distance from the center point, then the slingshot ball would go to the closest point to the cursor that is still within the distance, like this:

(if that makes sense)
the green circle is the slingshot ball, the black semi circle outline is the max distance, and the red is the slingshot.

1 Like

Is this UI or is the sling shot a model

1 Like

It’s a model 3d eeeeeeeeeeeeeeeeeeeeeeeeee

1 Like

Have you got it working so that the ball follows the cursor? If so just work out the direction from the origin to the ball then times that by the max distance you want the ball to go. Use .Unit to get the direction

1 Like

Yes, I’ve got it working, I will try that soon

1 Like
if  (TargetPosition - OriginPosition ).Magnitude > MaxDistance then
   NewPos = OriginPosition  + (TargetPosition - OriginPosition ).Unit * MaxDistance
end
2 Likes

Doesn’t seem to work, tried that and also tried adding the origin position to it aswell, but it just locks to a random position everytime. Is there a way to translate this into CFrame

1 Like

Thats odd. But yeh you could I guess

OriginPosition + CFrame.new(OriginPosition  ,TargetPosition ).LookVector * MaxDistance

maybe?

Scratch all that, how would I get the position in between the actual position and the position that is limited by the max distance, then subtract that position from the actual position?

Like that ( the red part with the arrow)