Jump to content

Sprite deceleration


GooseZA
 Share

Recommended Posts

Hi all, 

 

I'm making a little platformer and I want my character to slow down to a stop when no keys are pressed, rather than stop immediately. I'm using acceleration to get him moving up to his maxVelocity. There used to be a body.drag property that you could set apparently but this seems to no longer be there. 

 

Any ideas other than manually increasing / decreasing the velocity.x until it hits 0 if no keys are down?

 

 

 

 

Link to comment
Share on other sites

I know it sounds a bit hacky but you could try linear interpolation.

Have a static value for the velocity and when you are pressing the button leave the normal value for the interpolation to 1, when you stop pressing reduce the value (by for ex: 0.1) until it reaches 0. Then you'll have a smooth decreasing of the velocity until it stops.

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...