when it comes to making a game more realistic, I suck. I created a jump and move effect with the player, the only thing is when the player stops moving and you take your hand of the key to move him it is a very abrupt stop. I want to create an effect for the player to be able to slide a couple pixels after the player takes their hand off of the move key, but don't know where to start with this.
Thank you for any help!
I can see that you're using player.vy for gravity, which creates smooth movement on the y-axis. You can do the same for horizontal movement, by storing a player.vx and adding that to the x position each frame instead. If the player releases the key you can lerp the vx to zero.
if love.keyboard.isDown("left") then
player.vx = -player.speed
elseif love.keyboard.isDown("right") then
player.vx = player.speed
else
--Lerp functions are easy to implement, there are tons of libraries for this too
player.vx = lerp(player.vx, 0, delta)
end
player.x = player.x + player.vx * delta
Computer science student and part time game dev! Currently working on Depths of Limbo!
If you want to go really advanced/realistic, you can use acceleration (as evgiz points out, you're doing this already with gravity on the y axis), combined with friction. The friction will essentially put a cap on the velocity while the horizontal acceleration is still on, and it will drop the velocity to zero over time if the horizontal acceleration drops to zero (the player stops running). If you do some searches for friction on the forum, I think some people were recently talking about this & maybe even provided some code.