T
T
todoman2022-01-22 13:10:04
Unity
todoman, 2022-01-22 13:10:04

Why is the character walking in the wrong direction?

Hello, there is such a script for character movement in 3D:

using UnityEngine;

public class Controller : MonoBehaviour

{
    public float speed = 10f;
    public CharacterController characterController;

    Vector3 move;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        float horizontal = Input.GetAxis("Horizontal");
        float vertical = Input.GetAxis("Vertical");
        move = transform.forward * horizontal + transform.right * vertical;
        characterController.Move(move * speed * Time.deltaTime);
    }
}


When moving left or right, the character works correctly, and when pressed forward, it moves back and vice versa.
Thanks in advance, I always choose the best answer.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
U
Ukrainskiy, 2022-01-22
@todoman

Try like this:
float vertical = -Input.GetAxis("Vertical");

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question