1. Hey! Guest! The 32nd GMC Jam will take place between Feb 22nd, 12:00 UTC (Friday noon) and Feb 25th, 12:00 UTC (Monday noon). Why not join in! Click here to find out more!
    Dismiss Notice

GMS2 Attack jump bug where it hangs up

Discussion in 'Programming' started by ANewbee, Feb 11, 2019.

  1. ANewbee

    ANewbee Member

    Joined:
    Feb 11, 2019
    Posts:
    5
    cant seem to find any solutions :( heres the code
     
  2. ANewbee

    ANewbee Member

    Joined:
    Feb 11, 2019
    Posts:
    5
    Sorry for the low quality image, everytime i press jump with attack it suddenly does this stuck thingy where it continues to attack but is fix on a position, i cant move it after doing so.
     
  3. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,048
    You ever heard of copy-paste? Hard to put it all together with your code spread out across multiple images like that.
     
    ANewbee likes this.
  4. ANewbee

    ANewbee Member

    Joined:
    Feb 11, 2019
    Posts:
    5
    Was using a different computer sorry ;_;
    here.
    Code:
    Playerstate_normal:
    
    //Player Calculate Movement
    var move = key_right - key_left;
    
    hsp = move * walksp;
        
    vsp = vsp + grv;
    
    if (place_meeting(x,y+1,oWall)) && (key_jump)
    {
        vsp = -10;
    }
    
    
    
    //Horizontal Collision
    if (place_meeting(x+hsp,y,oWall))
    {
        while(!place_meeting(x+sign(hsp),y,oWall))
        {
            x = x + sign(hsp);
        }
        hsp = 0;
    }
    x = x + hsp;
    
    //Vertical Collision
    
    if (place_meeting(x,y+vsp,oWall))
    {
        
        while(!place_meeting(x,y+sign(vsp),oWall))
        {
            
            y = y + sign(vsp);
        }
        vsp = 0;
    }
    y = y + vsp;
    
    
    
    //Animations
    if (!place_meeting(x,y+1,oWall))
    {
        sprite_index = sExPlayerJump; //Jump anim
        image_speed = 0;
        if (sign(vsp) > 0 ) image_index = 1; else image_index = 0;
    }
    else
    {
        canjump = 10;
        if (sprite_index == sExPlayerJump) //Jump anim
        {
            if (audio_group_is_loaded(audiogroup_music))
            {
                audio_sound_pitch(snLanding,choose(0.8,1.0,1.2));
                audio_play_sound(snLanding,2,false);
                repeat(5)
                {
                    with (instance_create_layer(x,bbox_bottom,"Bullets",oDust))
                    {
                        vsp = 0;
                    }
                }
            }
        }
        
        image_speed = 1;
        if (hsp == 0)
        {
            sprite_index = sExPlayer; //Idle anim
        }
        else
        {
            sprite_index = sExPlayerRun; //Run anim
        }
    }
    
    if (hsp != 0) image_xscale = sign(hsp);
    if (key_attack) state = PLAYERSTATE.ATTACK_SLASH;
    /*/
    if ((key_attack) && (place_meeting(x,y+vsp,oWall))) {
        state = PLAYERSTATE.ATTACK_SLASH;
        while(!place_meeting(x,y+sign(vsp),oWall))
        {
            y = y + sign(vsp);
    
        }
        vsp = 0;
    }
    y = y + vsp;
    /*/
     
  5. ANewbee

    ANewbee Member

    Joined:
    Feb 11, 2019
    Posts:
    5
    Here are the other ones
    Code:
    Playerstate_normal:
    
    //Player Calculate Movement
    var move = key_right - key_left;
    
    hsp = move * walksp;
        
    vsp = vsp + grv;
    
    if (place_meeting(x,y+1,oWall)) && (key_jump)
    {
        vsp = -10;
    }
    
    
    
    //Horizontal Collision
    if (place_meeting(x+hsp,y,oWall))
    {
        while(!place_meeting(x+sign(hsp),y,oWall))
        {
            x = x + sign(hsp);
        }
        hsp = 0;
    }
    x = x + hsp;
    
    //Vertical Collision
    
    if (place_meeting(x,y+vsp,oWall))
    {
        
        while(!place_meeting(x,y+sign(vsp),oWall))
        {
            
            y = y + sign(vsp);
        }
        vsp = 0;
    }
    y = y + vsp;
    
    
    
    //Animations
    if (!place_meeting(x,y+1,oWall))
    {
        sprite_index = sExPlayerJump; //Jump anim
        image_speed = 0;
        if (sign(vsp) > 0 ) image_index = 1; else image_index = 0;
    }
    else
    {
        canjump = 10;
        if (sprite_index == sExPlayerJump) //Jump anim
        {
            if (audio_group_is_loaded(audiogroup_music))
            {
                audio_sound_pitch(snLanding,choose(0.8,1.0,1.2));
                audio_play_sound(snLanding,2,false);
                repeat(5)
                {
                    with (instance_create_layer(x,bbox_bottom,"Bullets",oDust))
                    {
                        vsp = 0;
                    }
                }
            }
        }
        
        image_speed = 1;
        if (hsp == 0)
        {
            sprite_index = sExPlayer; //Idle anim
        }
        else
        {
            sprite_index = sExPlayerRun; //Run anim
        }
    }
    
    if (hsp != 0) image_xscale = sign(hsp);
    if (key_attack) state = PLAYERSTATE.ATTACK_SLASH;
    /*/
    if ((key_attack) && (place_meeting(x,y+vsp,oWall))) {
        state = PLAYERSTATE.ATTACK_SLASH;
        while(!place_meeting(x,y+sign(vsp),oWall))
        {
            y = y + sign(vsp);
    
        }
        vsp = 0;
    }
    y = y + vsp;
    /*/
     
  6. ANewbee

    ANewbee Member

    Joined:
    Feb 11, 2019
    Posts:
    5
    Code:
    Playerstate_normal:
    
    //Player Calculate Movement
    var move = key_right - key_left;
    
    hsp = move * walksp;
        
    vsp = vsp + grv;
    
    if (place_meeting(x,y+1,oWall)) && (key_jump)
    {
        vsp = -10;
    }
    
    
    
    //Horizontal Collision
    if (place_meeting(x+hsp,y,oWall))
    {
        while(!place_meeting(x+sign(hsp),y,oWall))
        {
            x = x + sign(hsp);
        }
        hsp = 0;
    }
    x = x + hsp;
    
    //Vertical Collision
    
    if (place_meeting(x,y+vsp,oWall))
    {
        
        while(!place_meeting(x,y+sign(vsp),oWall))
        {
            
            y = y + sign(vsp);
        }
        vsp = 0;
    }
    y = y + vsp;
    
    
    
    //Animations
    if (!place_meeting(x,y+1,oWall))
    {
        sprite_index = sExPlayerJump; //Jump anim
        image_speed = 0;
        if (sign(vsp) > 0 ) image_index = 1; else image_index = 0;
    }
    else
    {
        canjump = 10;
        if (sprite_index == sExPlayerJump) //Jump anim
        {
            if (audio_group_is_loaded(audiogroup_music))
            {
                audio_sound_pitch(snLanding,choose(0.8,1.0,1.2));
                audio_play_sound(snLanding,2,false);
                repeat(5)
                {
                    with (instance_create_layer(x,bbox_bottom,"Bullets",oDust))
                    {
                        vsp = 0;
                    }
                }
            }
        }
        
        image_speed = 1;
        if (hsp == 0)
        {
            sprite_index = sExPlayer; //Idle anim
        }
        else
        {
            sprite_index = sExPlayerRun; //Run anim
        }
    }
    
    if (hsp != 0) image_xscale = sign(hsp);
    if (key_attack) state = PLAYERSTATE.ATTACK_SLASH;
    /*/
    if ((key_attack) && (place_meeting(x,y+vsp,oWall))) {
        state = PLAYERSTATE.ATTACK_SLASH;
        while(!place_meeting(x,y+sign(vsp),oWall))
        {
            y = y + sign(vsp);
    
        }
        vsp = 0;
    }
    y = y + vsp;
    /*/
     
  7. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    6,048
    You pasted the same code 3 times. lol Go back and fix your last two posts. :D

    But at a glance, do you have any movement code running in your attack state? If the movement code is all in your normal state, then you won't move at all while attacking. And if attackign in the air freezes you, that suggests 1) you ahve no movement code in any of your attack states, and 2) you for some reason aren't transitioning from your attack state to what I'd guess is supposed to be your normal state with gravity applied.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice