I am new to Unity and have been struggling with camera movement that must move freely within the x-z plane without ever changing the y-position. The camera is looking downwards (at 45 degree angle) toward the surface of a flattened cube that looks like a checkerboard (108 x 108).
The camera must remain at all times 36 units above this board and is pointing down 45 degrees from the x-z plane toward the board.
What I would like is to move the camera’s position in response to the Up Arrow in the direction of the camera’s x,z rotation ignoring the y rotation. This is probably not very clear. Think of a chessboard with an overhead camera directly over one corner but looking down and toward the far corner. When you press the Up Arrow, you move along the diagonal toward that far corner, but you don’t descend.
Below is what I have been exploring. All three attempts zoom down toward the checkerboard but are each moving properly in the x-z plane. Is there a way to retain the Y value in the Position when the camera is moved?
I’m sure this is a conceptual issue/roadblock of mine. All help appreciated.
#pragma strict
var _moveSpeed :float =10;
// this script is a component of the Main Camera
// Camera's position and orientation (via inspector) :
// Position is Vector3(54, 36, 55)
// Orientation is Vector3(45, 225, 0)
function Update () {
Maybe_Move();
}
function Maybe_Move () {
if (Input.GetKey(KeyCode.UpArrow)) {
// 1st
transform.position += transform.forward *_moveSpeed *Time.deltaTime;
// 2nd
//transform.Translate(Vector3.forward *_moveSpeed *Time.deltaTime);
// 3rd
//transform.position += Vector3(1,0,1) *_moveSpeed *Time.deltaTime);
}
}