Re: Smooth movement.
Posted: Fri Dec 18, 2015 8:13 pm
This piece of code:micha wrote:The key idea of smooth movement is to change velocity gradually not in jumps.First, ignore the math.min and look at that:Code: Select all
player.xvel = player.xvel * (1 - math.min(dt*player.friction, 1))
this can be expanded and you get:Code: Select all
player.xvel = player.xvel * (1 - dt*player.friction)
That means that the player's x-velocity is changed by (player.xvel*dt*player.friction). This term defines how fast the player slows down. You can see, that if the player is very fast, then he slows down fast. If he is slow (player.xvel almost zero) then the slowing down is slow.Code: Select all
player.xvel = player.xvel - player.xvel * dt * player.friction
Code: Select all
player.xvel = player.xvel * (1 - dt*player.friction)
Code: Select all
player.xvel = player.xvel - player.xvel * dt * player.friction
Code: Select all
1 - dt*player.friction
Code: Select all
player.xvel = player.xvel * y
So this means that the final result is going to be totally different micha