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?