Windows How do i add movement easing?



by movement easing i mean easing character movement, when i let go of the movement key, i want the character to slowly come to a halt, not just stop immediately.

What I've been trying to do is putting a loop on the speed of the character multiplied by 0.8, slowly decreasing their speed overtime, but i haven't quite figured out how to work that. Here's the code i tried:
Create event:
spd = 12
loop = 12*0.8 while (!instance_exists(obj_char)) repeat (100) {

spdease = 0.8
key_d = ord("D");
key_a = ord("A");

Step event:
spdease = 12*0.8
if(keyboard_check(key_d)) x += spd;
if(keyboard_check(key_a)) x -= spd;
if(keyboard_check(key_d)) {
keyboard_lastkey = key_d
if (keyboard_check(key_a)){
keyboard_lastkey = key_a

if(keyboard_check(vk_nokey))and keyboard_lastkey = key_d x += loop;
if(keyboard_check(vk_nokey))and keyboard_lastkey = key_a x -= loop;

(I've just started using game maker, if you can't already tell, haha.)


Why not just use Friction? You can set it to any rate you want and then reset it to 0 when you need to move again.
I usually have a small value that I subtract(or add if negative speed) until we are back at 0. Which is much simpler and works very well when done right.


Have something like this:

Spd = 0;
Max_spd = 6;
Acc = 0.5;
Decc = 1.


If keyboard_check(vk_right) {
If spd >=Max_spd {
Spd = Max_spd} else {
Spd += Acc
} else {
If spd >=0{
Spd - =Decc.

(typed on my phone, and from my head so could have some spelling mistakes)
I don't think you want "if spd >=0", that will decrease it even if it's at 0 so it will go negative.
But yeah, that's a very basic version of what I meant.


If you want to decrement an arbitrary value by another but don't want it to go below certain threshold, you'd decrease the speed like:
if(Spd > 0) Spd = max(Spd - Dec, 0);
meaning if speed is above zero, it is set to higher of: speed minus deceleration, or zero.


This is an old thread but in case someone looks for an answer. I have been using the following. It's from tutorial but don't remember from which one.

Create event:
ground_acc = 0.05;
run_speed = 5;

Step event:
var _move = keyboard_check(vk_right) - keyboard_check(vk_left)
hspeed = ground_acc * (_move * run_speed) + (1-ground_acc) * hspeed;