A
A
Alexey2020-09-18 19:39:48
C++ / C#
Alexey, 2020-09-18 19:39:48

Here is the code. The character does not move. What to do???

public class PlayerController : MonoBehaviour
{ 
    public float SpeedX;
    public float SpeedY;
     private void FixedUpdate()
     {
        float moveHorizontal= Input.GetAxis("Horizontal");
        float moveVertical = Input.GetAxis("Vertical");
        if (HorizontalMove > 0)
            sprt.flipX = false;
        else if (HorizontalMove < 0)
            sprt.flipX = true;
        rb.velocity = new Vector2(moveHorizontal * 
           SpeedX, moveVertical * SpeedX);
      }
}

Everything used to work, but I seem to have erased something and everything is broken.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dima Shcherbakov, 2020-09-19
@DimaScherb

Use the Character Controller component to create a character. The Character Controller has a Move() method.

Vector3 moveVector = new Vector3(0, 0, 0); // Вектор передвижения.
void CharMove(){ // Этот метод в Update
    moveVector = Vector3.zero;
    moveVector.x = Input.GetAxis("Horizontal") * MoveSpeed; 
    moveVector.y = Input.GetAxis("Vertical") * MoveSpeed;
    CharacterController.Move(moveVector * Time.deltaTime); // Метод движения по вектору передвижения.
}

Z
zZaKko, 2020-09-18
@zZaKko

"+=", not "=".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question