Horizontal Player movement with Unity velocity changes

Hey there :slight_smile:

Maybe some of you - as I do -, following the course in a more recent Unity version.
As of today in Unity 6000.x the “velocity” property become obsolete and changed to “linearVelocity” wich also can brake down directly to both X and Y axis.

  • linearVelocity - For X and Y axis
  • linearVelocityX - For X axis
  • linearVelocityY - For Y axis

To follow Rick’s instructions closer, can use the new Vector2 playerVelocity variable with linearVelocity as the following:

    void Run()
    {
        Vector2 playerVelocity = new Vector2 (moveInput.x * runSpeed, myRigidbody.linearVelocityY);
        myRigidbody.linearVelocity = playerVelocity;
    }

This will take in consideration both X and Y axis velocity of the RigidBody

My simple solution was to using linearVelocityX and get only the X axis value from the Vector2, without declaring a new Vector2 variable:

    void Run()
    {
       myRigidbody.linearVelocityX = moveInput.x * runSpeed;
    }

With linearVelocityX it will take only the X axis value from the Vector2