Hello,
It’s been three days and I still have no idea how to do this, so it’s time I start bothering you all.
My problem is as follows: imagine a simple terrain object with a camera over it at a certain angle (x:60, y:0, z:0), I managed to have this camera zoom in and out, rotate using a point in the middle of the screen corresponding to a position on the terrain, and move left and right whatever the curent rotation is.
But I absolutely don’t know how to have the camera move forward and back taking into account the current camera angle that may have changed due to rotation. I know it works with left and right movments because the x axis doesn’t change, still I do not knwow how to work with the camera’s angle when it comes to the two other movements.
CameraBehaviour.cs
private void Move (){
if (Input.GetKey(KeyCode.UpArrow) || Input.mousePosition.y>(ScreenHeight-ScreenLimit)){
transform.position += Vector3.forward * MoveSpeed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.DownArrow) || Input.mousePosition.y<ScreenLimit){
transform.position += Vector3.back * MoveSpeed * Time.deltaTime;
}
if (Input.GetKey(KeyCode.RightArrow) || Input.mousePosition.x>(ScreenWidth-ScreenLimit)){
transform.Translate(Vector3.right * MoveSpeed * Time.deltaTime);
}
if (Input.GetKey(KeyCode.LeftArrow) || Input.mousePosition.x<ScreenLimit){
transform.Translate(Vector3.left * MoveSpeed * Time.deltaTime);
}
}
Thanks a lot for your help!