Unity: character walks side by side instead of front

Asked

Viewed 402 times

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 mother-in-law:

I don’t know if it matters, but:

  • take a look here https://unity3d.com/pt/learn/tutorials/topics/scripting/translate-and-rotate

  • used the same script and continued the same error...

  • you just copied and pasted the code or watched the video to understand what you’re doing?

  • I had copied it and pasted it, but I saw the video and it didn’t help either

  • Your sidewalk ride... isn’t it because you built the object like this? Kind put the tank cannon on his side and made it wider than fulfilled?

2 answers

0

Observe the coordinate arrows, make sure your character is facing the X position, and do the following:

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

0

Exchange the GetAxis Vertical by Horizontal, thus:

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);
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.