GooseZA Posted February 23, 2014 Share Posted February 23, 2014 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 More sharing options...
Heppell08 Posted February 23, 2014 Share Posted February 23, 2014 Is it not possible lineardamping. Try setting:Player.linearDamping = 20;I know its used for water/low gravity stuff so might work for that to. Link to comment Share on other sites More sharing options...
GooseZA Posted February 23, 2014 Author Share Posted February 23, 2014 Thanks for the reply. I tried linear damping but that just seems to decrease the velocity to a fixed value once, rather than decreasing it repeatedly until 0. Link to comment Share on other sites More sharing options...
Felipe Posted February 23, 2014 Share Posted February 23, 2014 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 More sharing options...
Heppell08 Posted February 23, 2014 Share Posted February 23, 2014 Does not putting the linear damping in update not make it so that its constant no matter what or how many times pressed. Like if you have an update code. Like if the a key is justReleased, set the linear damping there to have it whenever the acceleration is released and/or isUp. Link to comment Share on other sites More sharing options...
Recommended Posts