Rotation and Character Controls Aren't Linked.

So, I have had trouble with this and can not find a valid solution, can anyone help with the code? the trouble is that when I rotate, the controls don’t update with the rotation so if I turn around, the controls are “S” to go forward, “W” for backward, “A” for right, and “D” for left. controls are swapped!

here’s my code.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerController : MonoBehaviour
{
public float runSpeed = 5f;
public float speedH = 2f;
public float speedV = 2f;
private float yaw = 0.0f;
private float pitch = 0.0f;
// Start is called before the first frame update
void Start()
{
runSpeed = 5f;
}
// Update is called once per frame
void Update()
{
transform.Translate(runSpeed * Input.GetAxis(“Horizontal”) * Time.deltaTime, 0f, runSpeed * Input.GetAxis(“Vertical”) * Time.deltaTime, 0f);
yaw += speedH * Input.GetAxis(“Mouse X”);
pitch -= speedV * Input.GetAxis(“Mouse Y”);
transform.eulerAngles = new Vector3(pitch, yaw, 0.0f);
}
}


Change the transform.translate line to this::

transform.Translate(transform.TransformDirection( runSpeed * Input.GetAxis("Horizontal") * Time.deltaTime, 0f, runSpeed * Input.GetAxis("Vertical") * Time.deltaTime, 0f));

The error happened because you were moving the player relative to the world, instead of relative to the direction they are facing.

The code didn’t work :frowning: when I pressed play compiler errors appear…

And we should read your mind? What was the “compiler error”?

I’m not sure where to find them compiling errors… but it just says compiling errors

  • Where does it say that?
  • If you have error you can see it in the “Console” window
  • You really should not use 2019.3 version of Unity, it is an alpha build. Go back to the 2018.4.X version (that’s the latest stable, supported version)

Thanks for the advice! i will try 2018 unity

also! will there be any errors with my game being made in 1019 and then switching to 2018?

Yes. Downgrade isn’t supported. You probably will have a bunch of errors.

Obviously it’s your decision to use an alpha software to develop or not, but you will have more problems with it since it is not intended for production yet. That’s why it is alpha build. If you can you should try to recreate your project in 2018.4 or 2019.1 (if you really want it, it’s mostly stable, but for beginners the LTS (.4) versions are better)

ok. I downgraded and got ALL the errors so I will just wait for updates to come and for more tutorials to shove information down my throat.