How can i make transform.RotateAround rotate only in a certain radius? I mean it would always rotate in the same radius and if the transform would somehow try to alter the radius it would imediately come back to the one I have set.
With questions like this one, 90% of the problem is figuring out what is really wanted. I’m not completely sure I’ve nailed what you wanted, but here is an explanation with a visual of what I’m suggestion…
So in figure 1, the red circle is orbiting around the blue hex. For the sake of the explanation, assume the red circle is at the max radius you want to allow for the orbit (grey line).
In figure 2, the blue hex moves. The movement here is exaggerated so the geometry can be seen. Assuming the blue hex is moving smoothly over time, then the movement from the previous frame will be slight. So after the movement, we construct a vector between the new position of hex and the circle. We do that by subtracting the position of the blue hex from the red circle.
var dir = transform.position - palydovs1.transform.position;
The green vector (dir) contains a direction and a length. It does not contain position information.
The next step (Figure 3) is to shorten the vector so it is at or less than the maximum radius.
dir = Vector3.ClampMagnitude(dir, dist);
In this case, you’ve assigned ‘dist’ to ‘circle.radius’. I’m assuming that is the largest amount you want the red circle to be from the blue hex. ClampMagnitude() will shorten the vector to the specified length if it is longer. If it is shorter, ClampMagnitude() does nothing (i.e. just returns the vector passed).
In Figure 4, the red circle is moved to the end of the now shortened green vector. We get that position by adding the position of the green arrow vector to the position of the blue hex.
transform.position = palydovs1.transform.position + dir;
RotateAround() will now have a new orbit that is no more than the maximum radius away from the blue hex. Again, the geometry here is exaggerated. Assuming the blue hex is moving over time, the results will many small changes frame to frame to keep the red circle in orbit at no more than the max radius.