I tried to take a screenshot of the error but when I do it shows that the sprite is correct. I think it's rapidly switching facing or doing both image xscales. It's weird because it sometimes pulls to the right as well like it has some horizontal speed. I cannot figure it out, and it feels like a glitch. I'm out of ideas.
obj_controller, create event
/// @desc game controller
global.left = (ord("A"));
global.right = (ord("D"));
global.jump = (ord("W"));
global.crouch = (ord("S"));
global.attack = (vk_up);
enum player_states
{
normal,
run,
fall,
jump,
crouch,
attack,
}
obj_player, create event
/// @desc define vars
depth = -10;
act_left = global.left;
act_right = global.right;
act_jump = global.jump;
act_crouch = global.crouch;
act_attack = global.attack;
/// MAXIMUMS
hor_speed_max = 5.0;
vert_speed_max = 20;
///boost_speed_max = 4;
/// X and Y speeds
hor_speed = 0;
vert_speed = 0;
/// FORCES
frict = .2;
accel = .25;
weight = 0.20;
///grav = 3;
jump_power = 15;
///boost_power = .10;
/// PLAYER STATE VARS
current_state = player_states.normal;
grounded = true;
_________________________________
obj_player, step event
/// @desc
action_left = keyboard_check(act_left);
action_right = keyboard_check(act_right);
action_jump = keyboard_check(act_jump);
action_crouch = keyboard_check(act_crouch);
action_attack = keyboard_check(act_attack);
cancel_left = keyboard_check_released(act_left);
cancel_right = keyboard_check_released(act_right);
/// Player facing
if (hor_speed > 0)
{
image_xscale = 1;
}
else if (hor_speed < 0)
{
image_xscale = -1;
}
/// Horizontal movement
if(action_left && !place_meeting(x - 1, y, obj_par_wall))
{
if(hor_speed > -hor_speed_max)
{
hor_speed -= accel;
}
}
else if(action_right && !place_meeting(x + 1, y, obj_par_wall))
{
if(hor_speed < +hor_speed_max)
{
hor_speed += accel;
}
}
/// Friction
if (!action_left && !action_right)
{
if(hor_speed != 0)
{
hor_speed -= sign(hor_speed) * frict;
}
}
if(!place_meeting(x + hor_speed, y, obj_par_wall))
{
x += hor_speed;
}
else
{
while(!place_meeting(x + sign(hor_speed), y, obj_par_wall))
{
x += sign(hor_speed);
}
hor_speed = 0;
}
/// Gravity
if(current_state != player_states.normal)
{
if(vert_speed < vert_speed_max)
{
vert_speed += weight;
}
}
if(!place_meeting(x, y + vert_speed, obj_par_wall))
{
y += vert_speed;
}
else
{
move_contact_solid(point_direction(x, y, x, y + vert_speed), vert_speed_max);
vert_speed = 0;
}
_________________________________
/// Player state switch
switch (current_state)
{
/// Case 1
case player_states.normal:
scr_normal();
break;
/// Case 2
case player_states.run:
scr_run();
break;
/// Case 3
case player_states.jump:
scr_jump();
break;
/// Case 4
case player_states.crouch:
scr_crouch();
break;
/// Case 5
case player_states.fall:
scr_fall();
break;
/// Case 6
case player_states.attack:
scr_attack();
break;
}
scr_player_animations();
_________________________________
scr_player_animations, script for controlling animations
/// @desc
animation = sprite_index;
switch (animation)
{
/// case 1
case player_states.normal:
sprite_index = spr_player_idle;
image_speed = 0;
break;
/// case 2
case player_states.run:
sprite_index = spr_player_run;
image_speed = 0;
break;
/// case 3
case player_states.jump:
sprite_index = spr_player_jump;
image_speed = 0;
break;
/// case 4
case player_states.fall:
sprite_index = spr_player_fall;
image_speed = 0;
break;
/// case 5
case player_states.attack:
sprite_index = spr_attack_air;
image_speed = 0;
break;
}
scr_normal, normal state script
/// @desc
grounded = true;
// switch to jump state
if(action_jump)
{
current_state = player_states.jump;
}
// swtich to fall state
if(!place_meeting(x, y + 1, obj_par_wall))
{
current_state = player_states.fall;
}
// switch to attack state
if(action_attack)
{
current_state = player_states.attack;
}
// switch to crouch state
if(action_crouch)
{
current_state = player_states.crouch;
}
scr_run, player run state script
/// @desc
if(cancel_left || cancel_right)
{
current_state = player_states.normal;
}
if(action_jump)
{
current_state = player_states.jump;
}
if(action_attack)
{
current_state = player_states.attack;
}
scr_jump, player jumping state script
/// @desc
y += -jump_power;
grounded = false;
if(vert_speed > 1)
{
current_state = player_states.fall;
}
if(action_attack)
{
current_state = player_states.attack;
}
if (place_meeting(x, y + 1, obj_par_wall))
{
current_state = player_states.normal;
}
scr_crouch, player crouching state script
/// @desc
grounded = true;
if(!action_crouch)
{
current_state = player_states.normal;
}
if(action_attack)
{
current_state = player_states.attack
}
scr_attack, player attack state script
/// @desc
if(!grounded)
{
sprite_index = spr_attack_air;
image_index = 0;
image_speed = 1;
}
else
{
sprite_index = spr_player_attack;
image_index = 0;
image_speed = 1;
}
if(ev_animation_end)
{
current_state = player_states.normal;
}
scr_fall, player falling state script
/// @desc
grounded = false;
if(place_meeting(x, y + 1, obj_par_wall))
{
current_state = player_states.normal;
}
if(action_attack)
{
current_state = player_states.attack;
}