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: