RigidBody2D jumping while moving issue

Hello.

I’m trying the rigidbody for the first time and I’m using rigidbody2D. I made the jump and it works fine, unless the character is moving. If I hold down the right arrow and moving and I jump, then the jump goes less than half the normal height.
Here is the code:

void ProcessMovement() {
		float hSpeed = Input.GetAxis("Horizontal");
		
		if(hSpeed == 0f) {
			Vector2 newVelocity = rigidbody2D.velocity;
			newVelocity.x = newVelocity.x /2;
			
			rigidbody2D.velocity = newVelocity;
		} else {
			rigidbody2D.AddForce(Vector2.right * hSpeed * moveForce);
		}
	}
void ProcessJump() {
		if(Input.GetButtonDown("Jump")){
			rigidbody2D.velocity = new Vector2(rigidbody2D.velocity.x, jumpForce);
			//rigidbody2D.AddForce(new Vector2(0, jumpForce));
		}
	}

I tried both AddForce and directly changing the speed, and both give me the same results. Also, both methods are in the FixedUpdate.

Here is a simple example that works for me, can you test it and see how it will behave for you.

	void Update () {

		float h = Input.GetAxis("Horizontal");
		rigidbody2D.AddForce(new Vector2(speed * Time.deltaTime * h, 0));

		if(Input.GetKeyDown(KeyCode.Space)) {
			rigidbody2D.AddForce(new Vector2(0,jumpforce));
		}
	}

It works. I found out that it only works when I multiply the horizontal force by Time.deltaTime, even in the FixedUpdate. Do I really need to multiply it in the FixedUpdate? I took this code from the unity 2D sample project, it works fine and it doesn’t add Time.deltaTime, but in my project it does not work without it, and I don’t understand why :confused:

I think the part where you divide the x-velocity by 2, when the user is not pressing the arrow keys might be messing things up.

The problem was happening before I added that. Anyway, I commented that out and it’s still happening. Any more ideas?