Hello, I wanted to add a bit of a gradual X-axis acceleration and deceleration to my player sprite, and I am having a slight issue with deceleration. When I release the movement keys, the character
almost stops, but inches ever so slightly to the right (A few pixels per second probably). This is how I'm doing it:
if(!isRightPressed && !isLeftPressed)
{
if(playerXVel > 0)
playerXVel -= 8;
if(playerXVel < 0)
playerXVel += 8;
}
I thought that these two statements would eventually neutralize each other and make the velocity zero, but I guess not.
That's all the code I think is necessary to post, because changing the lines inside the block to just
if(!isRightPressed && !isLeftPressed)
{
playerXVel = 0;
}
solves the problem but gets rid of the deceleration. How can I do this differently and fix the bug?