• 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!

GML Help Dashing and Attacking won't work on the ground!

BlueBot5000

Member
So as i go about following my tutorial


my rolling state won't work on the ground nor will attacking work on the ground as well how can i fix this so i can get on with my game!

if needed here's everything

Code:
switch (state)
{
   case "movement+gravity":
      #region Movement+Gravity State
      //Get The PLayer Inputs
      if keyboard_check(vk_right) and not place_meeting(x+4,y-1,objCollision)
      {
         x += 4;
         image_xscale = 1;
         sprite_index = sprBaraka_Run;
         image_speed = 0.7;
      }
  
      if keyboard_check(vk_left) and not place_meeting(x-4,y-1,objCollision)
      {
         x -= 4;
         image_xscale = -1;
         sprite_index = sprBaraka_Run;
         image_speed = 0.7;
      }
  
      if not keyboard_check(vk_right) and not keyboard_check(vk_left)
      {
         sprite_index = sprBaraka_Idle;
         image_speed = 1;
      }
    vspd = vspd + grv;
    key_jump = keyboard_check(ord("S"));
    key_jump_held = keyboard_check(ord("S"));

    //Jump
    if (place_meeting(x,y+1,objCollision)) and (key_jump)
    {
        vspd = -jumpspd;
    }
    //Small Jump
    if (vspd < 0 and !key_jump_held)
    {
        vspd = max(vspd, -jumpspd / jump_dampner);
    }

    if (!place_meeting(x+4,y+1,objCollision))
    {
        sprite_index = sprBaraka_InAir;
        image_speed = 0;
        if (vspd > 0) image_index = 1; else image_index = 0;
    }

    //Horizontal Collisions
    if (place_meeting(x+hspd,y,objCollision))
    {
        while (!place_meeting(x+sign(hspd),y,objCollision))
        {
            x = x + sign(hspd);
        }
        hspd = 0;

    }
    x = x + hspd;

    //Vertical Collisions
    if (place_meeting(x,y+vspd,objCollision))
    {
        while (!place_meeting(x,y+sign(vspd),objCollision))
        {
            y = y + sign(vspd);
        }
        vspd = 0;

    }
    y = y + vspd;

    if keyboard_check_pressed(ord("A"))
      {
         image_index = 0;
         state = "dash";
      }

      if keyboard_check_pressed(ord("D"))
      {
         image_index = 0;
         state = "attack one";
      }
      #endregion
      break;
  
   case "movement+gravitynodash":
      #region Movement+Gravity State
      //Get The PLayer Inputs
      if keyboard_check(vk_right) and not place_meeting(x+4,y-1,objCollision)
      {
         x += 4;
         image_xscale = 1;
         sprite_index = sprBaraka_Run;
         image_speed = 0.7;
      }
  
      if keyboard_check(vk_left) and not place_meeting(x-4,y-1,objCollision)
      {
         x -= 4;
         image_xscale = -1;
         sprite_index = sprBaraka_Run;
         image_speed = 0.7;
      }
  
      if not keyboard_check(vk_right) and not keyboard_check(vk_left)
      {
         sprite_index = sprBaraka_Idle;
         image_speed = 1;
      }
    vspd = vspd + grv;
    key_jump = keyboard_check(ord("S"));
    key_jump_held = keyboard_check(ord("S"));

    //Jump
    if (place_meeting(x,y+1,objCollision)) and (key_jump)
    {
        vspd = -jumpspd;
    }
    //Small Jump
    if (vspd < 0 and !key_jump_held)
    {
        vspd = max(vspd, -jumpspd / jump_dampner);
    }

    if (!place_meeting(x+4,y+1,objCollision))
    {
        sprite_index = sprBaraka_InAir;
        image_speed = 0;
        if (vspd > 0) image_index = 1; else image_index = 0;
    }

    //Horizontal Collisions
    if (place_meeting(x+hspd,y,objCollision))
    {
        while (!place_meeting(x+sign(hspd),y,objCollision))
        {
            x = x + sign(hspd);
        }
        hspd = 0;

    }
    x = x + hspd;

    //Vertical Collisions
    if (place_meeting(x,y+vspd,objCollision))
    {
        while (!place_meeting(x,y+sign(vspd),objCollision))
        {
            y = y + sign(vspd);
        }
        vspd = 0;

    }
    y = y + vspd;

    if keyboard_check_pressed(ord("D"))
      {
         image_index = 0;
         state = "attack one";
      }

    if (place_meeting(x,y+vspd,objCollision)) then state = "movement+gravity"
      #endregion
      break;

   case "dash":
      #region Dash State
      sprite_index = sprBaraka_Dash;
      image_speed = 3;
  
      if image_xscale == 1 and not place_meeting(x+10,y,objCollision)
      {
          x += 10;
      }
  
      if image_xscale == -1 and not place_meeting(x-10,y,objCollision)
      {
          x -= 10;
      }
      #endregion
      break;
  
    case "attack one":
      #region Dash State
      sprite_index = sprBaraka_Attack1;
      image_speed = 0.0006;
    vspd = vspd + grv;
    //Horizontal Collisions
    if (place_meeting(x+hspd,y,objCollision))
    {
        while (!place_meeting(x+sign(hspd),y,objCollision))
        {
            x = x + sign(hspd);
        }
        hspd = 0;

    }
    x = x + hspd;

    //Vertical Collisions
    if (place_meeting(x,y+vspd,objCollision))
    {
        while (!place_meeting(x,y+sign(vspd),objCollision))
        {
            y = y + sign(vspd);
        }
        vspd = 0;

    }
    y = y + vspd;
      #endregion
      break;
}
Animation End

Code:
if state == "dash"
{
    state = "movement+gravitynodash";
    image_index = 0;
}

if state == "attack one"
{
    state = "movement+gravity";
    sprite_index = sprBaraka_Attack1;
}
and heres the create event

Code:
hspd = 0;
vspd = 0;

grv = 0.2;
walkspd = 4;
jumpspd = 8;
jump_dampner = 4;
jumps = 0;

jumpsmax = 2;

key_down = 0;

state = "movement+gravity";
 

TheouAegis

Member
Check your sprites. Make sure the difference between bbox_bottom and y is the same across all sprites. If it isn't, you could be clipping into the ground when you change sprites and stopping because you are in a collision.
 

BlueBot5000

Member
It didn't work but just to clarify like anyone else i set my sprites to middle center and my Player object only uses the idle collision and even the idle collision is well within the canvas box
 

TheouAegis

Member
Middle-center means nothing. That is why I said make sure bbox_bottom-y is the same across all sprites. That's all that matters, not middle-center.

Comment out the collision checks in your dash state and your attack state. Test them then.

Only other thing I can think of is your regions are interfering. I don't see why they would, but I didn't make Game Maker.
 
Top