# Why is this unity camera moving in weird directions?

I have the following script

public class CameraScript : MonoBehaviour {

public bool AllowZoom;
public float zoom;
public float Speed;
Transform board;
void Start(){
board=GameObject.FindGameObjectsWithTag("PlayingBoard")[0].transform;
}

void Update(){
CentreRotate();
}
public void arrowMove(){
if(Input.GetKey(KeyCode.RightArrow)){

transform.Translate(transform.right*Speed*Time.deltaTime);
}
if(Input.GetKey(KeyCode.UpArrow)){
transform.Translate(transform.up*Speed*Time.deltaTime);
}
if(Input.GetKey(KeyCode.LeftArrow)){
transform.Translate(transform.right*-Speed*Time.deltaTime);
}
if(Input.GetKey(KeyCode.DownArrow)){
transform.Translate(transform.up*-Speed*Time.deltaTime);
}
}

public void CentreRotate(){
float distance=Mathf.Abs((transform.position-board.position).magnitude);
float toMove=distance-zoom;
transform.LookAt(board);
transform.Translate(transform.forward*toMove);
arrowMove();
}
}


This script should allow me to rotate around a given point at a constant distance from the center using the arrow keys. However rather then do that it seems to move towards a spot right above the board and then start turning really fast. It also seems that when slowing down the turning (by dividing distance by a large amount) that the arrow keys give "weird" directions, for example the right arrow key sometimes moves the camera forward.

Anybody got any ideas?

Here are some pictures of what is going on.

On startup:

After I press the right arrow key for a about a second:

• While much of your issue is coming from transform.Translate in your CentreRotate() method, there are all sorts of other problems that you are going to run into without refining your requirements and figuring out what exactly you want, which isn't really mentioned in your question. If you can rephrase your question to be more of a "How do I accomplish X?" providing details of what exactly should happen, maybe even images or a gif or two, that would put you in a much better spot. As it is this is a debug my code question which is off topic. – SpartanDonut Jun 17 '15 at 18:07
• Additionally, I asked and solved a similar problem that might be of use to you. It's not rotating around an object necessary but it results in a very similar effect to what you might be looking for (again, not entirely sure what it is you are looking for). gamedev.stackexchange.com/questions/89693/… – SpartanDonut Jun 17 '15 at 18:08