# How can I set the radius the object will rotate around the target?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TargetBehaviour : MonoBehaviour
{
// Add this script to Cube(2)
public GameObject Turret;//to get the position in worldspace to which this gameObject will rotate around.

[Header("The axis by which it will rotate around")]
public Vector3 axis;//by which axis it will rotate. x,y or z.

public float angle; //or the speed of rotation.

public float upperLimit, lowerLimit, delay;// upperLimit & lowerLimit: heighest & lowest height;
private float height, prevHeight, time;//height:height it is trying to reach(randomly generated); prevHeight:stores last value of height;delay in radomness;

// Update is called once per frame
void Update()
{
//Gets the position of your 'Turret' and rotates this gameObject around it by the 'axis' provided at speed 'angle' in degrees per update
transform.RotateAround(Turret.transform.position, axis.normalized, angle);
time += Time.deltaTime;
//Sets value of 'height' randomly within 'upperLimit' & 'lowerLimit' after delay
if (time > delay)
{
prevHeight = height;
height = Random.Range(lowerLimit, upperLimit);
time = 0;
}
//Mathf.Lerp changes height from 'prevHeight' to 'height' gradually (smooth transition)
transform.position = new Vector3(transform.position.x, Mathf.Lerp(prevHeight, height, time), transform.position.z);
}
}


Now it's rotating in a constant radius. I set the variable axis to 0,1,0

But if I want the object to rotate around the turret very close to it or very far ? I want to add a radius variable so I can change and set the radius.

This line: transform.RotateAround(Turret.transform.position, axis.normalized, angle); is saying rotate the cube around the turret. So if you want to rotate farther away you need to move the cube farther away. To do this first we find the current vector representing the current radius which would simply be position of the cube minus the position of the turret. This gives us the radius from the turret. Then let us say you want a radius of 40, this is the current radius normalized (the same vector but of length 1) multiplied by 40. So this will be the new radius from the turret. Should look something like this:

public float radius = 40;

void Start()
{