Hey, I made an orbital camera that rotates around my player, but the player doesn’t move relative to the camera. I’ve made it so that the player moves in the forward facing direction of the camera when you press W but I can’t figure out how to make the player move right, left, or down from the camera facing direction. Any ideas on how I can fix this?
Heres my script:
public Animator animator;
public float speed = 5.0f;
public float horizontalInput;
public float forwardInput;
// Update is called once per frame
void LateUpdate()
{
if (Input.GetKey(KeyCode.W))
{
horizontalInput = Input.GetAxis("Horizontal");
forwardInput = Input.GetAxis("Vertical");
this.transform.Translate(Vector3.forward * Time.deltaTime * speed);
this.gameObject.transform.rotation = Quaternion.Euler(0f, Camera.main.transform.eulerAngles.y, 0f);
animator.SetBool("Move", true);
}
if (Input.GetKey(KeyCode.S))
{
horizontalInput = Input.GetAxis("Horizontal");
forwardInput = Input.GetAxis("Vertical");
transform.Translate(Vector3.forward * Time.deltaTime * speed);
gameObject.transform.rotation = Quaternion.Euler(0f, 0f, 0f);
animator.SetBool("Move", true);
}
if (Input.GetKey(KeyCode.A))
{
horizontalInput = Input.GetAxis("Horizontal");
forwardInput = Input.GetAxis("Vertical");
transform.Translate(Vector3.forward * Time.deltaTime * speed);
gameObject.transform.rotation = Quaternion.Euler(0f, 90f, 0f);
animator.SetBool("Move", true);
}
if (Input.GetKey(KeyCode.D))
{
horizontalInput = Input.GetAxis("Horizontal");
forwardInput = Input.GetAxis("Vertical");
transform.Translate(Vector3.forward * Time.deltaTime * speed);
gameObject.transform.rotation = Quaternion.Euler(0f, -90f, 0f);
animator.SetBool("Move", true);
}
}