Unity: character walks sideways rather than head-on

4

Hi, I have a question on Unity3D 5!

My character, instead of moving forward, with WASD, he moves sideways. My script:

using UnityEngine;

public class PlayerController : MonoBehaviour
{
    void Update()
    {
        var x = Input.GetAxis("Horizontal") * Time.deltaTime * 150.0f;
        var z = Input.GetAxis("Vertical") * Time.deltaTime * 3.0f;

        transform.Rotate(0, x, 0);
        transform.Translate(0, 0, z);
    }
}

My inputManager:

Idonotknowifitmatters,but:

    
asked by anonymous 04.10.2018 / 19:05

2 answers

0

Look at the coordinate arrows, make sure your character is facing X, and do the following:

var x = Input.GetAxis("Vertical") * Time.deltaTime * 3.0f;
transform.Translate(x,0,0);
    
05.10.2018 / 19:58
0

Swap% with% Vertical by Horizontal, like this:

using UnityEngine;

public class PlayerController : MonoBehaviour
{
    void Update()
    {
        var x = Input.GetAxis("Horizontal") * Time.deltaTime * 150.0f;
        var z = Input.GetAxis("Horizontal") * Time.deltaTime * 3.0f;
        transform.Rotate(0, x, 0);
        transform.Translate(0, 0, z);
    }
}
    
16.11.2018 / 01:01