Not really sure how to word this but lets say you are a ball and are bouncing around and moving. Its a flat surface so everything moves fine.
Now introduce some 45 degree ramps. You fall on one straight down and bounce away from it. At the moment you can instantly move back regardless of how soon you hit it or what angle or speed your traveling at where it should be harder from the momentum of the push because it was at an angle. Kind of like a small gradual momentum until you reach 0 velocity, then you can move normally.
if (playerLeft)
{
float xVelocity = (playerBody.velocity.x > 0) ? playerBody.velocity.x - playerSpeed : -playerSpeed;
playerBody.velocity = new Vector3(xVelocity, playerBody.velocity.y, 0);
}
if (playerRight)
{
float xVelocity = (playerBody.velocity.x < 0) ? playerBody.velocity.x + playerSpeed : playerSpeed;
playerBody.velocity = new Vector3(xVelocity, playerBody.velocity.y, 0);
}
Originally i only had 1 line for each where i would set the x velocity equal to the player speed regardless if the velocity was -1 or -50. You can imagine how unrealistic that looks.
I tried adding the velocity which is what i did above. But because its minimum is only ever around 6 below 0. It will reach its max speed in 2 or 3 frames which isnt gradual enough.