I can't rotate a point around a pivot

public Vector3 RotatePointAroundPivot(Vector3 point, Vector3 pivot, Vector3 angles) {
Vector3 dir = point - pivot; // get point direction relative to pivot
dir = Quaternion.Euler(angles) * dir; // rotate it
point = dir + pivot; // calculate rotated point
return point; // return it
}

That is the method, and this is the calling code:

camera.transform.position = RotatePointAroundPivot(camera.transform.position,this.transform.position,new Vector3(0,5,0));

The script is attached to a cube, and I want to rotate the camera around it. The problem is, when I left click, I can see view shift slightly to the left for about half a second and then it comes back. What am I doing wrong?

Two things: 1) I overlooked that you also need to rotate the camera (using transform.LookAt is probably the easiest solution here) because all that script does is rotate the camera position around the object. 2) It seems to do that just fine, though, because a rotation of 5° should only result in a very small tilt. Try increasing the angle to get more visible results.

It doesn’t explain the camera moving back, but unless you’re having other functions moving the camera, that really shouldn’t happen.

The above code works. My problem was another piece of code that was translating the camera.