Lock object distance to the main object

So, this is something simple and yet haven’t been able to find a way to solve it, I’m quite new on this. I want my object to follow the mouse cursor, for which I used this:

	void Update () {
        Vector3 follow = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        follow.z = 5f;
        transform.position = follow;

But while it does, I want this smaller object movement to be restricted around a bigger object (Example: like a moon orbiting a planet) so when you move the mouse, it will simple rotate around this main object.

I mean I can simply do this:

        Vector3 allowedPos = follow - theCenter;
        allowedPos = Vector3.ClampMagnitude(allowedPos, 130.0f);
        transform.position = theCenter+ allowedPos;

but that would restrict the movement to a fixed radius, and I want it to be able to move further or closer to the main object, within a certain range. Is that possible?

Something like this?

public Transform ConstrainToZ; public float Radius; void Update () { Vector3 follow = Camera.main.ScreenToWorldPoint(Input.mousePosition); follow = new Vector3(follow.x - ConstrainToZ.position.x, follow.y - ConstrainToZ.position.y, ConstrainToZ.position.z); follow = follow.normalized * Radius; transform.position = ConstrainToZ.position + follow; }

by subtracting the position of the object you want to rotate around and then normalizing the vector, you get the direction relative to the bigger object. Then by multiplying it by a radius you constrain it to that distance from your desired object.