I could post the movement code with comments on how it works but it isn't like it is fully complete because it doesn't test for collisions; basically you'd use the collision_rectangle function to check the distance you are able to move unobstructed at the maximum speed. When this is used the code actually gets a small bit of revision so that when it detects nothing, instead of doing addition checks to see what specific objects that are being run into, it will just do the movement. Also the sprite flipping stuff I mentioned works but I just figured out that I have to set the x of origins of the sprites used to be about the middle of the sprite.
Anyway though he is the code for what I have posted so far with comments:
Create Event:
step_x = 0; //used to later determine how much character moves per step
acce_x = 0.4; //rate at which the character accelerates
dece_x = 0.2; //rate at which the character decelerates
move_x = 0; //the speed at which the character moves
maxi_x = 5; //the maximum speed at which the character can move
Step Event:
var hold_l,hold_r,absv_x;
//store the held values for the left and right keys
hold_l = keyboard_check(vk_left);
hold_r = keyboard_check(vk_right);
//if either only left or only right is pressed
if (hold_l ^^ hold_r){
//since direction 0 represents "right" the code below will be 0 if
//the left key is held, 180 represents "left"
direction = hold_l * 180;
//accelerate or decelerate a little more either left or right
move_x += (hold_r - hold_l) * acce_x;
//if the speed is less than its most negative allowed value
//or is greater than its most positive allowed value, then
//set the speed to be at its maximum respectively
if (move_x < -maxi_x)
move_x = -maxi_x;
else if (move_x > maxi_x)
move_x = maxi_x;
}
else if (move_x < 0) //if not holding left/right, slow down if moving left
move_x = min(move_x + dece_x,0);
else if (move_x > 0) //if not holding left/right, slow down if moving right
move_x = max(move_x - dece_x,0);
else //if not moving at all set it to be so you're not moving - this might actually not be necessary, lol, I don't know
move_x = 0;
//store the absolute value of the move speed so that you can work with it
absv_x = abs(move_x);
//if you have a move speed, the lowest value absv_x can be is 0 which represents no movement
if (absv_x){
//if you are at the max speed, clear out step_x so that it updates freshly
if (absv_x == maxi_x)
step_x = 0;
//add the movement speed to the number of times you move each step
step_x += absv_x;
//if your step_x is something like 2.4, you only move 2 times
while (step_x >= 1){
//you don't always move in the direction of your left/right key holding
//this handles the "drifting" and keeps it smooth
x += (move_x > 0) - (move_x < 0);
//this is necessary to get you out of the loop
step_x -= 1;
}
}