I’m trying to create an RTS style camera movement. So I have This script attached to my mainCamera.
using UnityEngine;
using System.Collections;
public class UserInput : MonoBehaviour
{
public float moveSpeed = 50f;
void Update ()
{
if(Input.GetKey(KeyCode.W))
transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
if(Input.GetKey(KeyCode.S))
transform.Translate(-Vector3.forward * moveSpeed * Time.deltaTime);
if(Input.GetKey(KeyCode.A))
transform.Translate(Vector3.left * moveSpeed * Time.deltaTime);
if(Input.GetKey(KeyCode.D))
transform.Translate(Vector3.right * moveSpeed * Time.deltaTime);
}
}
The Cameras rotation is angled to face slightly down. So when I press my keys, of course, the camera begins heading in the direction it’s facing. How to I have it head in the direction it’s facing but maintain the height of y?