I’m making an RTS game and want my camera to move along the ground with keyboard keys. However, it doesn’t work independently of camera angle, so if the camera is tilted and I press W it moves towards the ground, instead of forwards along the world plane. How can I make it so that it moves only back and forth in the xy-plane and not the direction it’s tilted?
Code:
Vector3 movement = new Vector3(speed * Time.deltaTime * Input.GetAxis(“Horizontal”), 0, speed * Time.deltaTime * Input.GetAxis(“Vertical”));
transform.Translate (movement);
The problem with this is that the x- and z-axis in the world space is always the same direction, so no matter which way the camera is looking it will move along the x-axis if I press W, and not move the way the camera is facing.