Attacking while Jumping

Zapzel-24

Member
Dear Game Maker community

I have been working a platformer game and been implementing an attack system. I have created a state machine to switch between Walking and attacking it works perfectly when pushing the Z button the character stops performs and does the attack animation and returns back to its walking script however I tried to make a code for attacking while jumping and it came out rather awkward when pushing the Z button while jumping or falling it locks to whatever vertical position its in, performs the attack animation and resumes falling I have tried everything I can think of to fix this issue from when its not place meeting the wall to implementing the code in the walking script in attempt to retain its jumping physics. I am just about stumped in this particular situation and now I have turn to the GM Community hoping I could find some answers.

NOTE: Please ignore the code SCR_Player_input that is just some basic input controls for the player.

Walking Script:
Code:
///scr_Player_Walking

//Input Script
scr_Player_Input()

//Calculate Movement
var move = move_right - move_left;

hsp = move * walksp;

vsp = vsp + grv;

if place_meeting(x,y+1,obj_wall) && (move_jump)
{
    vsp = -6;
}

//Horizontal Collision
if place_meeting(x+hsp,y,obj_wall)
{
    while (!place_meeting(x+sign(hsp),y,obj_wall))
    {
        x = x+sign(hsp);
    }
    hsp = 0;
}
x = x + hsp;

//Vertical Collision
if place_meeting(x,y+vsp,obj_wall)
{
    while (!place_meeting(x,y+sign(vsp),obj_wall))
    {
        y = y+sign(vsp);
    }
    vsp = 0;
}
y = y + vsp;

//Animation
if !place_meeting(x,y+1,obj_wall)
{
    sprite_index = spr_Durga_jumping;
    image_speed = 0;
    if (sign(vsp) > 0) image_index = 1; else image_index = 0;
}
else
{
    image_speed = 0.1;
    if (hsp == 0)
    {
        sprite_index = spr_Durga;
    }
    else
    {
        sprite_index = spr_Durga_walking;
    }
}

if (hsp != 0) image_xscale = sign(hsp);

//Attack State (Grounded)
if keyboard_check_pressed(ord('Z'))
{
    state = states.attack
}
Attack Script:
Code:
///scr_Player_Attack

//Input Script
scr_Player_Input();

//Horizontal Collision
if place_meeting(x+hsp,y,obj_wall)
{
    while (!place_meeting(x+sign(hsp),y,obj_wall))
    {
        x = x+sign(hsp);
    }
    hsp = 0;
}
x = x + hsp;

//Attack Animation (Grounded)
if state = states.attack && image_xscale = 1 && vsp = 0
{
    instance_create(x+18,y,obj_hitbox);
    sprite_index = spr_Durga_attack;
    image_speed = 0.5;
    hsp = 0;
}
else
{
    if state =states.attack && image_xscale = -1 && vsp = 0
    {
        instance_create(x-18,y,obj_hitbox);
        sprite_index = spr_Durga_attack;
        image_speed = 0.5;
        hsp = 0;
    }
}

//Attack Animation(Ariel)
if state = states.attack
{
    if image_xscale = 1
{
    instance_create(x+18,y,obj_hitbox);
    sprite_index = spr_Durga_attack;
    image_speed = 0.5;
}
else
{
    if image_xscale = -1
    {
        instance_create(x-18,y,obj_hitbox);
        sprite_index = spr_Durga_attack;
        image_speed = 0.5;
    }
}   
}

//Return to Walking Script
if (image_index > image_number -1)
{
    state = states.walking
    image_speed = 0.1;
}
 

Zapzel-24

Member
Ok, I got working correctly, the moment you mentioned the movement script I face palmed myself so hard. Game design can make you an absolute genius for figuring how the game works or an absolute retard for not noticing the obvious. Thank You very much ;)
 
Top