Whats is best for 2D movement Velocity or addForce?

Hi Folks,

So I have tried both Velocity and addForce but I’m not getting the result I was expecting which makes me wonder if I fully understand what they do.

void Update () {
       
        if(Input.GetKeyDown(KeyCode.Space)){
            rb.velocity = new Vector2(rb.velocity.x, jumpHeight);
        }

        if(Input.GetKeyDown(KeyCode.A)){
            rb.velocity = new Vector2(-moveSpeed, rb.velocity.y);
        }

        if (Input.GetKeyDown(KeyCode.D)){
            rb.velocity = new Vector2(moveSpeed, rb.velocity.y);
        }
    }
void FixedUpdate() {
           float x = Input.GetAxis("Horizontal");
           float y = Input.GetAxis("Vertical");
          
           rbody.velocity = new Vector2(x*speed, y*speed);
      }

So velocity when I press the key down (D or A) it stops after short time but addForce seems to do the same while that is set in FixedUpdate() which is confusing as I thought that would keep it moving till the key was released?
It also stops and I can press the key few more time with zero response from it which is very odd. Any ideas why?

Thanks.

This is because you are using GetKeyDown(), which is only called once on the frame that the key was pressed.

GetKey() is called on every frame that the key is held down, and is most likely what you want to use instead.

I have tested this but im now getting an odd issue.

Example: I press A to move left I release after the player stops and press the same A button again but nothing happens. I am also seeing an issue with the movement now that it stops at different distances any reason why that would happen?

Thanks