• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Why is my player freezing in midair when attacking?

Lightmind

Member
I've got a moving, jumping , and attacking player. He can attack on the ground fine, but when I jump and attack in midair, he freezes in midair, mid-animation, and im not sure why. Any help appreciated. This is my script:
GML:
if (attack) state = PLAYERSTATE.ATTACKSLASH;
Script code:
Code:
function PlayerState_Attack_Slash(){
    hsp = 0;
    
    // Start of the attack
    if (sprite_index != spr_player_atk) {
        sprite_index = spr_player_atk;
        image_index = 0;
        ds_list_clear(hit_by_attack);
    }
    
    // Use attack hitbox and check for hits
    mask_index = spr_player_atkHB;
    var hitByAttackNow = ds_list_create();
    var hits = instance_place_list(x, y, obj_enemy, hitByAttackNow, false);
    if (hits > 0) {
        for (var i = 0; i < hits; i ++) {
            // If this instance has not yet been hit by this attack
            var hitID = hitByAttackNow[| i];
            if (ds_list_find_index(hit_by_attack, hitID) == -1) {
                ds_list_add(hit_by_attack, hitID);   
                }
            }
        }
    

    ds_list_destroy(hitByAttackNow);
    mask_index = spr_player;

    if (animation_end()) {
        sprite_index = spr_player;
        state = PLAYERSTATE.FREE;
    }
    canattack = false;
    alarm[0] = room_speed * 0.2;
}
Sorry for not much information!
 

TheouAegis

Member
The simple answer is you are not running any movement code inside your attacking States. If you want to move, you need to run code that lets you move.
 

Lightmind

Member
The simple answer is you are not running any movement code inside your attacking States. If you want to move, you need to run code that lets you move.
How would I do that? Would I just copy + paste my movement code into it?

Edit: I fixed the freezing in midair, but the animation freezes in midair until he touches the ground, then it finishes the animation
 
Last edited:

Mightyjor

Member
How would I do that? Would I just copy + paste my movement code into it?

Edit: I fixed the freezing in midair, but the animation freezes in midair until he touches the ground, then it finishes the animation
just make sure your animation code is running during the attack as well
 
Top