# Rotatearaound a moving object

Hi!

I am trying to create a simple camera that would follow the player and only allow orbital movement sideways around the player. I have two pieces of code. Both work flawlessly on their own.

One for orbiting around the player:

``````void FixedUpdate()
{
Transform PC = GameObject.FindWithTag("Player").transform;
float p88re = Input.GetAxis("Kylgsuund");      // identify button press
float kiiruskonstant = 2f;            //fix orbiting speed
transform.RotateAround(PC.position, Vector3.up, kiiruskonstant * p88re);    //turn camera
}
``````

And the other for following the player:

``````{
public Transform target;            // The position that that camera will be following.
public float smoothing = 5f;        // The speed with which the camera will be following.

Vector3 offset;                     // The initial offset from the target.

void Start ()
{
// Calculate the initial offset.
offset = transform.position - target.position;
}

void FixedUpdate ()
{
// Create a postion the camera is aiming for based on the offset from the target.
Vector3 targetCamPos = target.position + offset;

// Smoothly interpolate between the camera's current position and it's target position.
transform.position = Vector3.Lerp (transform.position, targetCamPos, smoothing * Time.deltaTime);
}
}
``````

Which ever way I try to combine the two, the camera goes bananas, losing focus on the player and original rotation axis as soon as I move the character and try to rotate the camera. I just want the camera to follow the player, keeping the original distance and angle and moving around the player when axis movement is applied.

I’ve been stuck with this for two days now. Any and all pointers appreciated.

This issue with the first item is that when the player moves THEN you perform the rotate around.
Consider: player is at 0,0 and camera is at 0,1 aiming at the player.

Now, the player moves to 3,0. THEN you rotate the camera around this point: note that the radius of this rotation is greater than 1 (the original distance of the camera from the player)

I would suggest you adjust (translational-offset) the position of the camera at the same time (and by the same amount) that you adjust the player position. This will keep the distance and direction between the two objects the same. THEN do your rotate around.