Walking up an incline

I'm working on a simple platformer. The player is controlled like so, at each iteration of the game the player's horizontal velocity is set to 0, then, using a constant float called speed, speed is subtracted and added when the left and right arrows keys are down respectively, Mario Brother physics. This works when walking across a flat surface but when I walk up an incline, the moment I stop moving my character he jumps straight up in the air. I've assumed that this problem arises from the fact that I'm not really working with correct physics on the horizontal axis(instantaneously changing velocity), if I hold down the movement key as my player goes over the ramp then he jumps off moving in a parabola like a motorcycle or car. The problem seems simple enough but I'm not quite sure what the best way to solve it is.
how you set the speed? try with applytorque or allpyforce, or you'll break the code. if your player move while is on air is because you have to stop to apply the impulse (or force) when he is not on a platform. This is quite easy, you can use the ContactListener to be updated of every collision.
sorry for the strange explanation but i'm going to sleep 😁
I agree with lestofante that using the apply*() methods is a more durable way to handle movements, please try it so we can see if it makes a difference at all.

Anyway, if you could just know the slope of the shape you are moving over that you can alter the velocity you give your player. So on a slope you would give it less X speed and a little Y speed.
This is what I ended up using, I wondered if it's more convoluted then it needs to be. The *Down booleans indicate that an arrow key is down(checked in a processInput method) and groundNormal is set to null before calling step on the world and if the player collides with an object and the normal(from the player to the object) points down(normal dot negative unit y is at least zero) then it is saved in ground normal and jump is set to false. getLinearVelocityX() and getLinearVelocityY() are methods is made in a wrapper for Body and Vector is my own Vector class. jump is used so that I know when I jumped, so I can apply a downward force when I walk off a ramp to keep me from flying off like a motorcycle.

Code:
        Vector tempVector = groundNormal != null ? groundNormal : new Vector(0, -1);
        Vector groundTangent = tempVector.rotate((float)(Math.PI/2));
        if(!rightDown && !leftDown){
            if(groundNormal == null){
                body.applyForce(new Vector(-body.getLinearVelocityX()/delta, 0));
            }else{
                body.applyForce(body.getLinearVelocity().scale((body.getLinearVelocityX() < 0 ? 1 : -1)*groundTangent.dot(body.getLinearVelocity().normalise())/delta));
            }
        }else{
            if(rightDown){
                groundTangent = groundTangent.scale((speed-body.getLinearVelocityX())/groundTangent.getX()/delta);
                body.applyForce(groundTangent);
                direction = Direction.Right;
            }else if(leftDown){
                groundTangent = groundTangent.scale((-speed-body.getLinearVelocityX())/groundTangent.getX()/delta);
                body.applyForce(groundTangent);
                direction = Direction.Left;
            }
        }

        if(upDown && groundNormal != null){
            tempVector = new Vector(0, (terminalVelocity - body.getLinearVelocityY())/delta);
            tempVector = tempVector.scale(body.getMass()*-groundNormal.getY());
            body.applyForce(tempVector);
            jump = true;
        }
       
        if(!jump && body.getLinearVelocityY() > 0){
            body.applyForce(new Vector(0, -body.getLinearVelocityY()/delta));
        }


Edit: I just noticed that my character seems to jump higher when it stands still on a incline, does anyone have any ideas? This is how my body is built, or most of it, things are kind of spread around in my project.

Edit 2: Ok, I was multiplying my force vector for jumping by mass but nothing else, which seemed to be causing problems. But the jumping still seems to be a little nonuniform for different inclines.

Code:
bodyDef.setFixedRotation(true);
...
hitbox = new PolygonDef();
hitbox.addVertex(new Vector(15/getGame().getPixelsPerMeter(), 0));
hitbox.addVertex(new Vector(40/getGame().getPixelsPerMeter(), 0));
hitbox.addVertex(new Vector(40/getGame().getPixelsPerMeter(), 34/getGame().getPixelsPerMeter()));
hitbox.addVertex(new Vector(15/getGame().getPixelsPerMeter(), 34/getGame().getPixelsPerMeter()));
hitbox.setDensity(2);
hitbox.setFriction(0);
hitbox.setRestitution(0);
hitbox.setGroupIndex(-1);
body.createShape(hitbox);
body.setMassFromShapes();

Original thread: https://box2d.org/forum/viewtopic.php?t=4890