Why my player can't move ?

Hello, my player can’t move. I’m can’t understand why, please help me.

Code

void Start () {
    rb = GetComponent<Rigidbody>();
  
}

void Update()
{

    float moveHorizontal = Input.GetAxis("Horizontal");
    float moveVertical = Input.GetAxis("Vertical");
    Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical);
    rb.velocity = movement;

}

}

Try using rb.addForce(movement);

If you don’t notice much movement, try multiplying each vector in movement by a speed variable to increase the movement.

There are a few problems:

  • You are not using FixedUpdate() for physics calculations.
  • You are not using Time.deltaTime to make this consistent.
  • Input.GetAxis() only returns values between -1 and 1, so the velocity will be slow.

Here is revised code:

void Start()
{
    rb = GetComponent<Rigidbody>();
}

void FixedUpdate()
{
    float speed = 10.0f;

    float moveHorizontal = Input.GetAxis("Horizontal");
    float moveVertical = Input.GetAxis("Vertical");

    Vector3 movement = new Vector3(moveHorizontal, 0.0f, moveVertical) * speed * Time.deltaTime;
    rb.velocity = movement;
}

Ofcourse, you need to have a rigidbody attached as well.