What i want is a script to move the Cube(2) around the Turret and to be close to the Turret in circles nonstop automatic. The Cube(2) is the object to move in circles. The turret is the Cube.
Just moving the Cube(2) is not a problem but how to make it move in a smooth circles around the turret(Cube) ?
And the height of Cube(2) not should change i mean close to the turret(Cube) can be also up in the air so it will move in circles in this height. The Cube(2) Y position not should be change. Just the circles he move in to be small and too big radius.
Here is the code you need. It is well defined. Tell me if something goes wrong
public class Answer : MonoBehaviour {
// Add this script to Cube(2)
[Header("Add your turret")]
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.
[Header("Angle covered per update")]
public float angle; //or the speed of rotation.
// 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, angle);
}
}